You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
a.concat(b) pushes the elements of b to a, so the actual behavior is correct (also, what the functions do at runtime is JavaScript-world, not TypeScript). Your expected behavior happens if you use push instead or add extra brackets around [2, 'two']:
My concern primarily lies with the fact that it was so easy to violate type safety. It would be nice if this showed up in the editor rather than something I had to debug at runtime.
I'm working on it, but I've encountered the following error after doing the change:
src/compiler/core.ts:840:42-errorTS2345: Argumentoftype 'SortedArray<T>' is not assignable to parameter of type 'ReadonlyArray<T>'.Typesofproperty 'concat' areincompatible.Type'(...items: (T | ConcatArray<T>)[]) => T extends ConcatArray<infer E> ? (E | T)[] : T[]'isnotassignabletotype'(...items: (T | ConcatArray<T>)[]) => T extends ConcatArray<infer E> ? (E | T)[] : T[]'.Twodifferenttypeswiththisnameexist,buttheyareunrelated.Type'T extends ConcatArray<infer E> ? (E | T)[] : T[]'isnotassignabletotype'T extends ConcatArray<infer E> ? (E | T)[] : T[]'.Twodifferenttypeswiththisnameexist,buttheyareunrelated.840constinsertIndex=binarySearch(array,insert,identity,compare);~~~~~
...and a bunch of errors of the form Argument of type 'T[]' is not assignable to parameter of type 'ReadonlyArray<T>'. This seems to be a bug, or am I overlooking something @mhegazy?
Activity
Ghabriel commentedon Oct 27, 2017
a.concat(b)
pushes the elements ofb
toa
, so the actual behavior is correct (also, what the functions do at runtime is JavaScript-world, not TypeScript). Your expected behavior happens if you usepush
instead or add extra brackets around[2, 'two']
:or
andyfriesen commentedon Oct 27, 2017
This is absolutely true.
My concern primarily lies with the fact that it was so easy to violate type safety. It would be nice if this showed up in the editor rather than something I had to debug at runtime.
mhegazy commentedon Jul 16, 2018
One option is to change the definition of
concat
to be:mhegazy commentedon Jul 16, 2018
PRs welcomed
Ghabriel commentedon Jul 17, 2018
I'm working on it, but I've encountered the following error after doing the change:
...and a bunch of errors of the form
Argument of type 'T[]' is not assignable to parameter of type 'ReadonlyArray<T>'
. This seems to be a bug, or am I overlooking something @mhegazy?mhegazy commentedon Jul 17, 2018
did you change the declaration of both Array and ReadonlyArray?
andersk commentedon Jan 26, 2019
Another example:
and a related issue with
flatMap
:RyanCavanaugh commentedon Jan 31, 2020
Rolling up into #36554
concat
has wrong typization #58631