What is “not assignable to parameter of type never” error in typescript?

前端 未结 10 2194
無奈伤痛
無奈伤痛 2020-12-04 15:08

Code is:

const foo = (foo: string) => {
  const result = []
  result.push(foo)
}

I get the following TS error:

[t

10条回答
  •  攒了一身酷
    2020-12-04 15:32

    I got the same error in ReactJS function component, using ReactJS useState hook. The solution was to declare the type of useState at initialisation:

    const [items , setItems] = useState([]); // replace IItem[] with your own typing: string, boolean...
    

提交回复
热议问题