Skip to content

Unwrap substitutions on conditional check types before comparing them #43888

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
May 5, 2021

Conversation

weswigham
Copy link
Member

Fixes #43123

The outer conditional was creating a substitution on [0], making it look like [0] & [0, any?] at the inner conditional, which 1. didn't unwrap right (since we determine syntactically that we should be able to unwrap the tuple types made), and 2. produces a subtype of what the user actually wrote for the check type, which can alter results unexpectedly. By unwrapping substitutions at check type positions, we avoid this issue.

@typescript-bot typescript-bot added Author: Team For Milestone Bug PRs that fix a bug with a specific milestone labels Apr 29, 2021
@andrewbranch
Copy link
Member

  1. didn't unwrap right (since we determine syntactically that we should be able to unwrap the tuple types made), and 2. produces a subtype of what the user actually wrote for the check type

I’m assuming it was (1) that made the inner conditional evaluate to false? If we are going from substitution types to their actual type in the check type position, won’t that potentially start making a lot more conditional types evaluate to false? I can’t come up with a compelling example (I mean, even the repro in the bug report is reduced to something totally theoretical, not practical), so I might be thinking about this wrong.

@weswigham weswigham merged commit b83148f into microsoft:master May 5, 2021
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
Development

Successfully merging this pull request may close these issues.

in conditional type, type parameter T is inferred as X, but [X] extends [T] is false
4 participants