Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.9k views
in Technique[技术] by (71.8m points)

typescript 解构 怎么给类型?

image

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

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

不重命名怎么写呢


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

  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) => {

  }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...