Skip to content

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

Merged
sandersn merged 1 commit into
microsoft:masterfrom
dragomirtitian:GH-35431
Mar 11, 2021
Merged

Fixes non-null assertion applied to type narrowed to never not issuing an error.#35863
sandersn merged 1 commit into
microsoft:masterfrom
dragomirtitian:GH-35431

Conversation

@dragomirtitian
Copy link
Copy Markdown
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
Comment thread src/compiler/checker.ts Outdated
… 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
@microsoft microsoft locked as resolved and limited conversation to collaborators Oct 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

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