Skip to content

Commit 5efd8ee

Browse files
committed
Include type parameter defaults in contextual typing
1 parent 9a83f25 commit 5efd8ee

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/compiler/checker.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27534,7 +27534,7 @@ namespace ts {
2753427534
const inferenceContext = getInferenceContext(node);
2753527535
// If no inferences have been made, nothing is gained from instantiating as type parameters
2753627536
// would just be replaced with their defaults similar to the apparent type.
27537-
if (inferenceContext && contextFlags! & ContextFlags.Signature && some(inferenceContext.inferences, hasInferenceCandidates)) {
27537+
if (inferenceContext && contextFlags! & ContextFlags.Signature && some(inferenceContext.inferences, hasInferenceCandidatesOrDefault)) {
2753827538
// For contextual signatures we incorporate all inferences made so far, e.g. from return
2753927539
// types as well as arguments to the left in a function call.
2754027540
return instantiateInstantiableTypes(contextualType, inferenceContext.nonFixingMapper);
@@ -35145,6 +35145,10 @@ namespace ts {
3514535145
return !!(info.candidates || info.contraCandidates);
3514635146
}
3514735147

35148+
function hasInferenceCandidatesOrDefault(info: InferenceInfo) {
35149+
return !!(info.candidates || info.contraCandidates || hasTypeParameterDefault(info.typeParameter));
35150+
}
35151+
3514835152
function hasOverlappingInferences(a: InferenceInfo[], b: InferenceInfo[]) {
3514935153
for (let i = 0; i < a.length; i++) {
3515035154
if (hasInferenceCandidates(a[i]) && hasInferenceCandidates(b[i])) {

0 commit comments

Comments
 (0)