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
Through this I found #26412, which may be related to this, but I can't quite tell, in part because a code example that it claims raises a compile error in TS 3.0 no longer raises a compile error in 4.4.3. There appear to be a number of bugs related to that, but as far as I can tell, none of them match the particular problem I'm having. I might have missed one, though, in which case I apologize.
🕗 Version & Regression Information
4.4.3. Also happens in 4.5.0-dev.20210930 (see playground link below).
This is the behavior in every version I tried, and I reviewed the FAQ for entries containing the word extends and spread.
typeThing={hello: number[];}functionoperateOnThingViaSpreadThenAssignment<TextendsThing>(thing: T): T{constnewThing={ ...thing};// Here we are assigning a string instead of number[] to the "hello" property,// and TS raises a compile error as expected.newThing.hello="hi";returnnewThing;}functionoperateOnThingViaSpreadOnly<TextendsThing>(thing: T): T{// Here we are assigning a string instead of number[] to the "hello" property,// but TS doesn't complain.return{ ...thing,hello: "hi"};}
🙁 Actual behavior
TypeScript appears to treat the two functions differently, correctly raising a compilation error for operateOnThingViaSpreadThenAssignment() while curiously being fine with operateOnThingViaSpreadOnly().
The latter seems particularly bad because, as far as I can tell, it's effectively not reporting something that is actually a type error.
🙂 Expected behavior
I expect TypeScript to raise the same error--or at least, something very similar, along the lines of Type 'string' is not assignable to type 'number[]'--for both functions.
The text was updated successfully, but these errors were encountered:
There’s a bug report template you’re supposed to fill out when you open an issue here. Could you edit your post and provide all the required information? This includes search terms you presumably used when looking for existing issues on the same topic before opening a new one. Thanks!
Bug Report
🔎 Search Terms
typescript extends spread
Through this I found #26412, which may be related to this, but I can't quite tell, in part because a code example that it claims raises a compile error in TS 3.0 no longer raises a compile error in 4.4.3. There appear to be a number of bugs related to that, but as far as I can tell, none of them match the particular problem I'm having. I might have missed one, though, in which case I apologize.
🕗 Version & Regression Information
4.4.3. Also happens in 4.5.0-dev.20210930 (see playground link below).
This is the behavior in every version I tried, and I reviewed the FAQ for entries containing the word
extends
andspread
.⏯ Playground Link
Here is a Playground link.
💻 Code
🙁 Actual behavior
TypeScript appears to treat the two functions differently, correctly raising a compilation error for
operateOnThingViaSpreadThenAssignment()
while curiously being fine withoperateOnThingViaSpreadOnly()
.The latter seems particularly bad because, as far as I can tell, it's effectively not reporting something that is actually a type error.
🙂 Expected behavior
I expect TypeScript to raise the same error--or at least, something very similar, along the lines of
Type 'string' is not assignable to type 'number[]'
--for both functions.The text was updated successfully, but these errors were encountered: