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
interfaceITest{value: number;};letx: ITest[]=[{value: 10}];x={ ...x};// no type check error, but is an object instead of an arrayx={ ...[{value: 10}]}// no type check error, but is an object instead of an arrayx={"0": {value: 10}};// type check error, is correctx={"0": {value: 10}, ...[]};// no type check error, but is an object instead of an arrayx=[{value: 10}];// no type check error, is correct
🙁 Actual behavior
Type checker does ignore the outer object literal when using the spread operator even though the type is supposed to be an array.
🙂 Expected behavior
Type checker should recognise the outer type if the spread operator is used and raise a mismatched type error.
The text was updated successfully, but these errors were encountered:
@MartinJohns@RyanCavanaugh I see that this is a duplicate of what is discussed in the later parts of #9726 but I do not quite understand why it falls under the same topic as #9726 was initially created for. I see that it might cause the issue in some tangled ways, but would it not still be much easier to fix than the origina #9726 ? The type checker would just have to look at the outer type (Array or Object literal) to decide that there is a type mismatch. The inner type is checked correctly anyways, why not check the out type too? (Sorry, if I have a simplistic view about it, but currently I have no deeper insight about the type checking constraints there ...)
Bug Report
The type checker seems to fail to check the outer type when a spread operator is used .
🔎 Search Terms
repo:microsoft/TypeScript spread type not checked array to object
ts spread operator outer type check fails
ts bug spread operator fails when cast to object instead of array
🕗 Version & Regression Information
Tested on the playground with version 5.1.6, 5.0.4, 4.9.5, 3.9.7
⏯ Playground Link
TS Playground
There is also this Stack Overflow Question about it.
💻 Code
🙁 Actual behavior
Type checker does ignore the outer object literal when using the spread operator even though the type is supposed to be an array.
🙂 Expected behavior
Type checker should recognise the outer type if the spread operator is used and raise a mismatched type error.
The text was updated successfully, but these errors were encountered: