Skip to content

Fix narrow-by-constructor logic #37698

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

Merged
merged 2 commits into from
Mar 31, 2020
Merged

Fix narrow-by-constructor logic #37698

merged 2 commits into from
Mar 31, 2020

Conversation

ahejlsberg
Copy link
Member

This PR fixes two issues in the narrow-by-constructor logic that was added in #32774:

  • Removes unnecessary resetting of control flow type to the declared type.
  • Reorganizes logic and adds a missing isMatchingReference check, the absence of which would cause constructor checks to erroneously narrow all references in the code path.

Fixes #37660.

@ahejlsberg ahejlsberg merged commit 2b0f351 into master Mar 31, 2020
@ahejlsberg ahejlsberg added this to the TypeScript 3.9.1 milestone Mar 31, 2020
@ahejlsberg
Copy link
Member Author

@RyanCavanaugh We should pull this fix into the next 3.9 release.

@jakebailey jakebailey deleted the fix37660 branch November 7, 2022 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[3.9.0-beta] Type gets incorrectly un-narrowed after ifs
2 participants