debugtypescriptCritical
What is "not assignable to parameter of type never" error in TypeScript?
Viewed 0 times
errortypescriptassignablewhatparameternevernottype
Problem
Code is:
I get the following TS error:
What am I doing wrong? Is this a bug?
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?
Solution
All you have to do is define your
Without defining the array type, it by default will be
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.Code Snippets
const result : string[] = [];Context
Stack Overflow Q#52423842, score: 1160
Revisions (0)
No revisions yet.