TypeScript: Confusing type error message in `concat`
Typechecking this code:
var x: string[] = ["A","B","C"];
x = x.concat([1,2,3])
will throw up with
Argument of type 'number[]' is not assignable to parameter of type 'string'.
This happens even without the x = assignment, and that shows that it would make more sense if the error was either of:
Argument of type 'number' is not assignable to parameter of type 'string'.
or
Argument of type 'number[]' is not assignable to parameter of type 'string[]'.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 16 (12 by maintainers)
Commits related to this issue
- Merge pull request #6629 from LPGhatguy/master Update Array.concat type signature to fix #6594 — committed to microsoft/TypeScript by mhegazy 8 years ago
@SlurpTheo I prefer
concatbecause it does not modify the original array. At any rate, the two are not equivalent.