npmtypescript95% confidence\u2191 905

What is "not assignable to parameter of type never" error in TypeScript?

Full error message
Code is:

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

I get the following TS error:

[ts] Argument of type 'string' is not assignable to parameter of type 'never'.

What am I doing wrong? Is this a bug?

All you have to do is define your result as a string array, like the following: const result : string[] = []; Without defining the array type, it by default will be never. So when you tried to add a string to it, it was a type mismatch, and so it threw the error you saw.

API access

Get this solution programmatically \u2014 free, no authentication.

curl https://depscope.dev/api/error/1932690ac1a3c616aadda74dc42f9212a6443ed2e5be9ba65ec18701f7a0ad54
hash \u00b7 1932690ac1a3c616aadda74dc42f9212a6443ed2e5be9ba65ec18701f7a0ad54
What is "not assignable to parameter of type never&quot… — DepScope fix | DepScope