[5.3] Type narrowing regression with property comparison to boolean false #56482
Labels
Bug
A bug in TypeScript
Fix Available
A PR has been opened for this issue
Recent Regression
This is a new regression just found in the last major/minor version of TypeScript.
Milestone
π 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: