Skip to content

Commit 31551fd

Browse files
committed
Only instantiate types if we need to
1 parent 19bdaf8 commit 31551fd

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/compiler/checker.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10383,11 +10383,11 @@ namespace ts {
1038310383
// We attempt to resolve the conditional type only when the check and extends types are non-generic
1038410384
if (!checkTypeInstantiable && !maybeTypeOfKind(inferredExtendsType, TypeFlags.Instantiable | TypeFlags.GenericMappedType)) {
1038510385
if (inferredExtendsType.flags & TypeFlags.AnyOrUnknown) {
10386-
return instantiateType(root.trueType, combinedMapper || mapper);
10386+
return combinedMapper ? instantiateType(root.trueType, combinedMapper) : trueType;
1038710387
}
1038810388
// Return union of trueType and falseType for 'any' since it matches anything
1038910389
if (checkType.flags & TypeFlags.Any) {
10390-
return getUnionType([instantiateType(root.trueType, combinedMapper || mapper), falseType]);
10390+
return getUnionType([combinedMapper ? instantiateType(root.trueType, combinedMapper) : trueType, falseType]);
1039110391
}
1039210392
// Return falseType for a definitely false extends check. We check an instantiations of the two
1039310393
// types with type parameters mapped to the wildcard type, the most permissive instantiations
@@ -10402,7 +10402,7 @@ namespace ts {
1040210402
// type Foo<T extends { x: any }> = T extends { x: string } ? string : number
1040310403
// doesn't immediately resolve to 'string' instead of being deferred.
1040410404
if (isTypeAssignableTo(getRestrictiveInstantiation(checkType), getRestrictiveInstantiation(inferredExtendsType))) {
10405-
return instantiateType(root.trueType, combinedMapper || mapper);
10405+
return combinedMapper ? instantiateType(root.trueType, combinedMapper) : trueType;
1040610406
}
1040710407
}
1040810408
// Return a deferred type for a check that is neither definitely true nor definitely false

0 commit comments

Comments
 (0)