-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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 generic function types #16305
Conversation
will miss this shirt #13039 (comment) |
const instantiatedType = instantiateType(contextualType, cloneTypeMapper(getContextualMapper(node))); | ||
// If the contextual type is a generic pure function type, we instantiate the type with | ||
// its own type parameters and type arguments. This ensures that the type parameters are | ||
// not erased to type any during type inference such that they can be inferred as actual |
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.
type 'any'
// Inferences made from return types have lower priority than all other inferences. | ||
inferTypes(context.inferences, instantiatedType, returnType, InferencePriority.ReturnType); | ||
const instantiatedType = instantiateType(contextualType, cloneTypeMapper(getContextualMapper(node))); | ||
// If the contextual type is a generic pure function type, we instantiate the type with |
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.
What is meant by "generic pure function type"?
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.
A type that has nothing but a single call signature.
With this PR we do not erase the type parameters of contextual generic function types. Instead, the type parameters are allowed to propagate into the contextually typed expression. For example:
Previously, contextual generic function types were ignored and
a
would therefore have been of typeany
.This PR also expands upon #16072 to permit the contextual type of a generic function to itself be a generic function type. For example:
Fixes #16293.