-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Enable exhaustiveness checking and never narrowing for non-union types #62114
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
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Run npx hereby runtests-parallel
, waiting 20 minutes for it to finish, and then accept the baseline diff, and commit that
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
Completed as requested. Ran |
@typescript-bot test it |
@typescript-bot Unfortunately I hit an unexpected error while processing your comment. I've automatically reported this to GitHub. You can ask me to try again later by mentioning me in a new comment. If you want to contact GitHub about this error, please mention the following identifier so they can better serve you: Sorry for the inconvenience! |
Hey @RyanCavanaugh, the results of running the DT tests are ready. There were interesting changes: Branch only errors:Package: ws
|
@typescript-bot Unfortunately I hit an unexpected error while processing your comment. I've automatically reported this to GitHub. You can ask me to try again later by mentioning me in a new comment. If you want to contact GitHub about this error, please mention the following identifier so they can better serve you: Sorry for the inconvenience! |
@RyanCavanaugh Here are the results of running the user tests with tsc comparing Something interesting changed - please have a look. Details
|
@typescript-bot Unfortunately I hit an unexpected error while processing your comment. I've automatically reported this to GitHub. You can ask me to try again later by mentioning me in a new comment. If you want to contact GitHub about this error, please mention the following identifier so they can better serve you: Sorry for the inconvenience! |
@RyanCavanaugh Here they are:
tscComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
@typescript-bot Unfortunately I hit an unexpected error while processing your comment. I've automatically reported this to GitHub. You can ask me to try again later by mentioning me in a new comment. If you want to contact GitHub about this error, please mention the following identifier so they can better serve you: Sorry for the inconvenience! |
@RyanCavanaugh Here are the results of running the top 400 repos with tsc comparing Something interesting changed - please have a look. Details
|
@typescript-bot Unfortunately I hit an unexpected error while processing your comment. I've automatically reported this to GitHub. You can ask me to try again later by mentioning me in a new comment. If you want to contact GitHub about this error, please mention the following identifier so they can better serve you: Sorry for the inconvenience! |
This PR fixes an issue where TypeScript failed to properly narrow types to
never
when all possibilities were eliminated for non-union types, particularly affecting single-member enums and objects with literal properties.Problem
Previously, TypeScript only performed discriminant property narrowing on union types. This meant that for cases like:
The issue occurred because
getDiscriminantPropertyAccess
required union types to enable narrowing logic.Solution
Extended the discriminant property narrowing logic in
getDiscriminantPropertyAccess
to also work with non-union types that have literal/unit-like properties. This enables the existing narrowing machinery to correctly identify impossible cases and narrow them tonever
.The fix is minimal and surgical - it only adds an additional path for non-union types while preserving all existing behavior for union types.
Testing
Fixes #23572.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.