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
constlist=['A','B','C']asconst;functionabc(char: 'A'|'B'|'C'|'D'){if(list.includes(char)){// errors herereturn;}if(char=='B'){}// should error here// do something with char}
for TS to recognize that I'm not trying to assign types in the wrong places
and instead to detect that the following comparison appears to be unintentional if (value == 'B') { }
I want it to act like this:
functionabc(char: 'A'|'B'|'C'|'D'){if(char=='A'||char=='B'||char=='C'){return;}if(char=='B'){}// do something with char}
Additional information about the issue
I'm trying to add an early exit at the start of the function
and I want the type system to reflect that char will no longer be 'A', 'B', 'C'
but instead it just tries to insult me
The text was updated successfully, but these errors were encountered:
π Search Terms
type narrow
π Version & Regression Information
since forever
β― Playground Link
https://www.typescriptlang.org/play/?ts=5.9.0-dev.20250322#code/MYewdgzgLgBANgS2jAvDA2gcgIKYDQyYBC+hAwpgLowCGEMokUA3AFCsBmArmMFAuFoAjYAApgACxoAnAFyFcMAD6ESy8pnWYAIpgCUMAN6sYMBBxijE0AHQJecLgBMAphHFTpeg4ZgB6PxgXaWkQaXoJYJcTUxhpFyguaTA2UwBfdlNzS0kZVDRifSMYNP9AiAkQLjgnIJCwmEj4mJiAmCcQGAgQAFsEiXsAcxgAdwQoCQZPVgygA
π» Code
π Actual behavior
TS complains about assignability
π Expected behavior
for TS to recognize that I'm not trying to assign types in the wrong places
and instead to detect that the following comparison appears to be unintentional
if (value == 'B') { }
I want it to act like this:

Additional information about the issue
I'm trying to add an early exit at the start of the function
and I want the type system to reflect that
char
will no longer be'A', 'B', 'C'
but instead it just tries to insult me
The text was updated successfully, but these errors were encountered: