Improve contextual typing by generic rest parameters#30114
Improve contextual typing by generic rest parameters#30114ahejlsberg merged 4 commits intomasterfrom
Conversation
| // outer call expression. Effectively we just want a snapshot of whatever has been | ||
| // inferred for any outer call expression so far. | ||
| const instantiatedType = instantiateType(contextualType, cloneTypeMapper(getContextualMapper(node))); | ||
| const instantiatedType = instantiateType(contextualType, cloneTypeMapper(getContextualMapper(node), InferenceFlags.NoDefault)); |
There was a problem hiding this comment.
The cloneTypeMapper call used to create the returnType mapper inside call resolution doesn't pass InferenceFlags.NoDefault with this change. Intentional?
There was a problem hiding this comment.
Yes, it's intentional. We only want the InferenceFlags.NoDefault behavior here (because we're transposing inferences from the outer call mapper and don't want an absence of inferences in the outer mapper to turn into what appears to be a concrete inference of the default).
This PR improves contextual typing by generic rest parameters such that we can infer a tuple type from the function expression or arrow function being contextually typed while simultaneously assigning contextual parameter types to the function expression or arrow function. Consider:
In the examples above, the type inferred for
Ais[],[any],[any, any], and[number]respectively. Previously, in all but the last example we'd inferany[]forA.