-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Contextual typing for return expressions of functions with contextual signatures based on instantiated types #61185
base: main
Are you sure you want to change the base?
Conversation
… signatures based on instantiated types
@jakebailey would you be so kind and run tests here? :) |
9055e55
to
a45dfbb
Compare
// prevent inference candidates of outer inference context to provide contextual type information for the expressions within the inner context | ||
// that could turn fresh literal candidates in the inner context into regular types for union-like literals (such as booleans and enums) | ||
// and that would create mismatches between inferred types for outer and inner contexts which is especially problematic when invariant type parameters are involved | ||
// | ||
// the call below should be ok but with the inner one receiving `boolean` as contextual type it would infer `true` for its type parameter | ||
// and that would create outer signature applicability error with outer `Box<boolean>` and inner `Box<true>` | ||
// | ||
// interface Box<T> { v: (arg: T) => T; } | ||
// declare function invariantBox<T>(v: T): Box<T> | ||
// declare function fn<T>(arg: Box<T>, get: () => Box<T>): void; | ||
// fn(invariantBox(true), () => invariantBox(true)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this problem is quite similar to #48363 , #59754 and #61196
So it feels like some consistent approach could be used to fix those and to remove this branch. But that problem is out of the scope of this PR so I'm not attempting to deal with it. Thanks to this branch the behavior should be no worse than the existing one.
This expands on #30568 (in a way)
fixes #61197