Skip to content
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

Add assignability rules for when the target is a conditional type #27932

Closed

Conversation

weswigham
Copy link
Member

Inspired by looking into #27014
Fixes #26933
Steals from #27589

This adds assignability rules for relating types when the target is a conditional type. We only check for conditional type target assignability when:

  • The target is not distributive or,
  • The distributive conditional type's check type cannot be instantiated to never
    Given these circumstances, a type is assignable to the conditional in question if
  • it is assignable to both branches of the conditional, or
  • if the conditional type looks to be always true (yet has infer types, preventing simplification) and it is assignable to the intersection of the instantiated constraint of the true branch and the uninstantiated constraint (this allows for "independent" infer types to not interfere with true branch assignability, whilst still preserving the assignment-blocking part of the existential-like behavior of the infer types).

@weswigham weswigham force-pushed the infer-conditional-class-this branch from 7652906 to f590103 Compare October 17, 2018 02:10
@jack-williams
Copy link
Collaborator

jack-williams commented Oct 23, 2018

When you write:

it is assignable to the intersection of the instantiated constraint of the true branch and the uninstantiated constraint.

By instantiated are you referring to the instantiation of the infer parameters? Would it be possible to write a small example that shows the difference between the proposed behaviour, and the behaviour if you only consider the uninstantiated true constraint (as opposed to the intersection)?

I have a hard time translating the rules into concrete examples, so it would be greatly appreciated!

@dgreensp
Copy link

dgreensp commented Jan 8, 2020

Does this address the unsoundness in #26945?

@sandersn
Copy link
Member

This experiment is pretty old, so I'm going to close it to reduce the number of open PRs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team Experiment A fork with an experimental idea which might not make it into master
Projects
None yet
Development

Successfully merging this pull request may close these issues.

T should be assignable to A extends B ? C : D if it is assignable to both C and D
5 participants