-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Possible Regression in v4.9: Conditionals using Unlisted Property Narrowing with the in Operator #52812
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This code is confusing to reason about because it is written in a way that presupposes an invariant violation occurring somewhere along the way. Our logic effectively thinks of it this way: In "noWork", it goes like this:
In "work", it goes like this:
The functions don't make any sense if you assume the types are closed, which is the only operative condition in which using |
It's interesting to me that in the "working" case, TS never considers the possibility that |
thank you so much for your thoughtful explanation. π |
Bug Report
π Search Terms
v4.9 conditionals unlisted property narrowing in operator #50666
π Version & Regression Information
v4.9+, including nightly
working in v4.8.4
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
In the
noWork
function, typescript could not narrow down the type to beingHandledResult
. When the or clause is switched, it works. SinceBoolean(A || B) === Boolean(B || A)
this seems like an error.π Expected behavior
The ordering of the conditionals should not impact the narrowing of the type.
The text was updated successfully, but these errors were encountered: