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 spread of a Set into an object is assignable to a Set. This shouldn't be allowed, because the object isn't a Set. tsc should be able to detect this at compile time.
🔎 Search Terms
set spread
🕗 Version & Regression Information
This is the behavior in the version I tried (3.3.3, 4.6.2, 5.0.4, 5.1.0-dev.20230411), and I reviewed the FAQ for entries about Common "Bugs" That Aren't Bugs
This is the behavior in every version I tried, and I reviewed the FAQ for entries about Sets and spreads
constmy_set1: Set<number>=newSet();// The type of my_set2 is actually Object.// tsc doesn't detect this, and thinks it's a `Set<number>`.constmy_set2: Set<number>={...my_set1};// This will fail at runtime because my_set2 isn't a Set.my_set2.has(2);
🙁 Actual behavior
tsc doesn't detect the type error.
🙂 Expected behavior
tsc should detect the type error.
The text was updated successfully, but these errors were encountered:
This is a more general limitation than implied - { ...new A() } (for some class A) likewise isn’t an A, but TS thinks it is because structural typing. I'm thinking this will probably be considered a design limitation and not a bug.
Yeah, { ...x } is always assumed to be the same type of x. Non-enumerability isn't tracked anyway, and expanding it out into { a: x.a, b: x.b, c: x.c } etc breaks a bunch of scenarios that people rightly expect to work.
Bug Report
A spread of a Set into an object is assignable to a Set. This shouldn't be allowed, because the object isn't a Set. tsc should be able to detect this at compile time.
🔎 Search Terms
set spread
🕗 Version & Regression Information
This is the behavior in the version I tried (3.3.3, 4.6.2, 5.0.4, 5.1.0-dev.20230411), and I reviewed the FAQ for entries about Common "Bugs" That Aren't Bugs
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
tsc doesn't detect the type error.
🙂 Expected behavior
tsc should detect the type error.
The text was updated successfully, but these errors were encountered: