Skip to content

Redo in narrowing for intersections #39637

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
Jul 30, 2020

Conversation

sandersn
Copy link
Member

This fixes the breaking change from the 3.9 beta by adding a simple exemption for typeof globalThis. It does not do the more complicated fix of exempting optional properties from in-narrowing; I'm going to look at that next, but I need to convince myself whether it'll actually help.

Fixes #37039
Fixes #38162 (mostly)

sandersn added 2 commits July 15, 2020 14:59
Still need to carve out an exception for globalThis
@sandersn
Copy link
Member Author

I re-read #38162 and the preceding bugs. The core problem is that that in-narrowing is guaranteed to be wrong a lot in the most common use case (optional properties), regardless of whether it's in an intersection. Without missing in the type system, we're just choosing whether to be wrong-strict or wrong-permissive.

Switching between the two is (1) probably not possible or worthwhile because of backward compatibility (2) a separate issue from making the feature work with intersections. I think this PR is ready to go as-is.

@sandersn sandersn merged commit d3877d2 into master Jul 30, 2020
@sandersn sandersn deleted the redo-in-narrowing-for-intersections branch July 30, 2020 21:58
@typescript-bot typescript-bot added Author: Team For Milestone Bug PRs that fix a bug with a specific milestone labels Jul 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Milestone Bug PRs that fix a bug with a specific milestone
Projects
None yet
3 participants