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

Most upvoted comments

@SlurpTheo I prefer concat because it does not modify the original array. At any rate, the two are not equivalent.