Skip to content

Fixes non-null assertion applied to type narrowed to never not issuing an error. #35863

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 1 commit into from
Mar 11, 2021

Conversation

dragomirtitian
Copy link
Contributor

Fixed issue where non null assertion caused getFlowTypeOfReference to return the declared type if the type was already narrowed to never.

This was caused by the fact that getTypeWithFacts(resultType, TypeFacts.NEUndefinedOrNull) will return never both if resultType was already never and if resultType does not contain undefined or null. In the latter case returning the declaring type is correct, in the former case this causes something narrowed to never to still be typed as the original declared type.

Fixes #35431

@sandersn sandersn added the For Backlog Bug PRs that fix a backlog bug label Feb 3, 2020
@sandersn sandersn requested review from ahejlsberg, sandersn and weswigham and removed request for sandersn March 10, 2020 21:59
@dragomirtitian dragomirtitian force-pushed the GH-35431 branch 2 times, most recently from 1de0ae1 to 07698d7 Compare February 12, 2021 20:52
… return the declared type if the type was already narrowed to never.

This was caused by the fact that getTypeWithFacts(resultType, TypeFacts.NEUndefinedOrNull) will return never both if resultType was already never and if resultType does not contain undefined or null. In the latter case returning the declaring type is correct, in the former case this causes something narrowed to never to still be typed as the original declared type.
@sandersn sandersn merged commit 71661b9 into microsoft:master Mar 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Backlog Bug PRs that fix a backlog bug
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

! type assertion on never changes the type
4 participants