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
functionprocessStrings(input: {[index: string]: string}){// Expecting an object with values of string type (with `length` property)for(varkeyinObject.keys(input))console.log(input[key].length);}functiontest(parameters: {[index: string]: string|number}){varmyStuff={...{asd: "qwe"}, ...parameters};// No errors here, while `myStuff` clearly can contain numbersprocessStrings(myStuff)varmyStuff2={...parameters};// When leaving out the other object, the error is now correctly determinedprocessStrings(myStuff2)}// Providing an object with value of number typetest({"key": 123});
π Actual behavior
The myStuff variable doesn't receive the predictable {[index: string]: string | number} type, therefore the script crashes at runtime
π Expected behavior
The myStuff variable should receive the predictable {[index: string]: string | number} type, therefore the IDE or the compiler should show errors about this
The text was updated successfully, but these errors were encountered:
Spread is currently modeled using intersection types, which sometimes produces the wrong type. To model this correctly TS would need a dedicated type operator for spread.
Spread is currently modeled using intersection types, which sometimes produces the wrong type. To model this correctly TS would need a dedicated type operator for spread.
So, this is a known TS limitation. Thank you for the clarification!
Yeah, specifically the limitation is that TS models { ...t, ...u } as T & U, but this is wrong when t and u have overlapping properties (a string index signature is considered to overlap with everything for this purpose).
Bug Report
π Search Terms
spread operator
object types
π Version & Regression Information
Version 4.8.4
Version 5.0.0-dev.20221103
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
The
myStuff
variable doesn't receive the predictable{[index: string]: string | number}
type, therefore the script crashes at runtimeπ Expected behavior
The
myStuff
variable should receive the predictable{[index: string]: string | number}
type, therefore the IDE or the compiler should show errors about thisThe text was updated successfully, but these errors were encountered: