typescript 解构 怎么给类型?

image

这个类型要怎么写。。我知道解构重命名的写法,

const handleClick = ({item:rename}:{item:string}):void => {}

不重命名怎么写呢

阅读 21.5k
2 个回答

以下三种写法,可以参考:

  const handleMenuClick = ({item, key, keyPath}: {item: Object, key: string, keyPath:string}) => {

  }
  const handleMenuClick = ({item, key, keyPath}: any) => {

  }
  interface SomeObj {
    item: Object
    key: string
    keyPath:string
  }
  const handleMenuClick1 = ({item, key, keyPath}: SomeObj) => {

  }

其实换个写法就行

image.png

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题