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
When using a switch statement inside of a loop, it creates weird intersection issues, which should be union types. This causes issues where types are never, or just not correct in general.
z is assignable to g, but data[key] is not assignable to this[key] despite being exactly the same type. key is already narrowed down to the correct keys "content" | "tts".
🙁 Actual behavior
When using intelisense, it seems that type is correctly using |. However, when TRULY assigning to this it seems to have created a union instead (& is not correct).
🙂 Expected behavior
It should stay as a union instead.
The text was updated successfully, but these errors were encountered:
apacheli
changed the title
Switch inside loop is converting to intersection
Switch inside for loop is converting to intersection
Jan 15, 2022
Bug Report
When using a
switch
statement inside of a loop, it creates weird intersection issues, which should be union types. This causes issues where types arenever
, or just not correct in general.🔎 Search Terms
switch case, loop, union intersection, assigning
🕗 Version & Regression Information
TypeScript 4.5
⏯ Playground Link
playground link
💻 Code
z
is assignable tog
, butdata[key]
is not assignable tothis[key]
despite being exactly the same type.key
is already narrowed down to the correct keys"content" | "tts"
.🙁 Actual behavior
When using intelisense, it seems that type is correctly using
|
. However, when TRULY assigning tothis
it seems to have created a union instead (&
is not correct).🙂 Expected behavior
It should stay as a union instead.
The text was updated successfully, but these errors were encountered: