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

前端 未结 10 2200
無奈伤痛
無奈伤痛 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:37

    One more reason for the error.

    if you are exporting after wrapping component with connect()() then props may give typescript error
    Solution: I didn't explore much as I had the option of replacing connect function with useSelector hook
    for example

    /* Comp.tsx */
    interface IComp {
     a: number
    }
    
    const Comp = ({a}:IComp) => 
    {a}
    /* ** below line is culprit, you are exporting default the return value of Connect and there is no types added to that return value of that connect()(Comp) ** */ export default connect()(Comp) -- /* App.tsx */ const App = () => { /** below line gives same error [ts] Argument of type 'number' is not assignable to parameter of type 'never' */ return }

提交回复
热议问题