-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
[5.3] Type narrowing regression with property comparison to boolean false #56482
Comments
It looks very much related to my change: #53714 . I'll investigate this soon. Thanks for the issue report! |
Here's a different reproduction resembling the one we have in our project, maybe you find it helpful:
EDIT: I tested it with the nightly version of TS from your PR and yes, it's fixed there. |
This issue has a lot of thumbs up; out of curiosity, are people finding this naturally? Or is there some Twitter thread that's directing people here? The original PR didn't fail any of the extended test suites, so it's somewhat surprising to me to have a regression like this. |
My guess is that it was posted on a companyβs Slack channel or smth and a couple of devs from that channel +1ed this π |
Please file a new issue |
π Search Terms
narrowing, strict equals, property access, boolean false, undefined
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play?ts=5.3.1-rc#code/JYOwLgpgTgZghgYwgAgGIHt3IN4ChnIBGcUAXEZgDYRwi4C+uuC6IAzmMgOYRgZYBeZAAoAlOX7IAPsgCuIACYQYoCAuQCAfDnzIovWVBDIAsnDAALAHRRaC9AFsxybQAYrAVmQB+HERLk8JRsKPTI5PJKKiBqDEws7JwwmBrcvPxiuMAwIsno3lbEUBoCQkEhojoECWzo1FaU6FzCeaJxuAD0HcgAAmBsALQQAB4ADhAIYENQUOjFA8h5yMBsyKPobGzAhJQAnnKKyqoKzKy19Y3NeYUkbUA
π» Code
π Actual behavior
In line 13 and following,
foo
is incorrectly narrowed to justFoo
(whereas it was previouslyFoo | undefined
), although we learned nothing about it from the precedingif
as that did not influence control flow.π Expected behavior
TS should report an error when accessing
foo.bar
asfoo
can potentially be undefined.Additional information about the issue
I originally discovered this issue in JSX with a snippet similar to:
There as well, the access
foo.bar
is allowed due to the preceding check, although they are completely separate.Note that changing it to
=== true
or removing the checks entirely fixes the problem.The text was updated successfully, but these errors were encountered: