Skip to content

Change typeof narrowing to narrow selected union members #25243

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 5 commits into from
Sep 6, 2018

Conversation

weswigham
Copy link
Member

And to intersect even in the subtype case so keyof T narrows to keyof T & string and not string.

Fixes #25179

@@ -367,15 +367,15 @@ function test14(a: boolean | number | void) {
if (typeof a === "boolean") {
>typeof a === "boolean" : boolean
>typeof a : "string" | "number" | "boolean" | "symbol" | "undefined" | "object" | "function"
>a : number | boolean | void
>a : undefined
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is kind of a scary diff - is there an observable breaking change we need to document?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a started as boolean | number | void - it then for narrowed against undefined (which actually matches the void case - and void & undefined is apparently just undefined). Previously we just missed that narrowing opportunity. And naturally, undefined narrowed by boolean simply becomes never below, like one would hope!

@weswigham
Copy link
Member Author

Reviewer advice: Review with the ignore whitespace box checked.

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.

2 participants