Skip to content

Commit 3efcfcb

Browse files
authored
Cache getConstraintOfDistributiveConditionalType (#53358)
1 parent b34371a commit 3efcfcb

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/compiler/checker.ts

+6
Original file line numberDiff line numberDiff line change
@@ -13605,6 +13605,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1360513605
}
1360613606

1360713607
function getConstraintOfDistributiveConditionalType(type: ConditionalType): Type | undefined {
13608+
if (type.resolvedConstraintOfDistributive !== undefined) {
13609+
return type.resolvedConstraintOfDistributive || undefined;
13610+
}
13611+
1360813612
// Check if we have a conditional type of the form 'T extends U ? X : Y', where T is a constrained
1360913613
// type parameter. If so, create an instantiation of the conditional type where T is replaced
1361013614
// with its constraint. We do this because if the constraint is a union type it will be distributed
@@ -13622,10 +13626,12 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1362213626
if (constraint && constraint !== type.checkType) {
1362313627
const instantiated = getConditionalTypeInstantiation(type, prependTypeMapping(type.root.checkType, constraint, type.mapper));
1362413628
if (!(instantiated.flags & TypeFlags.Never)) {
13629+
type.resolvedConstraintOfDistributive = instantiated;
1362513630
return instantiated;
1362613631
}
1362713632
}
1362813633
}
13634+
type.resolvedConstraintOfDistributive = false;
1362913635
return undefined;
1363013636
}
1363113637

src/compiler/types.ts

+2
Original file line numberDiff line numberDiff line change
@@ -6645,6 +6645,8 @@ export interface ConditionalType extends InstantiableType {
66456645
/** @internal */
66466646
resolvedDefaultConstraint?: Type;
66476647
/** @internal */
6648+
resolvedConstraintOfDistributive?: Type | false;
6649+
/** @internal */
66486650
mapper?: TypeMapper;
66496651
/** @internal */
66506652
combinedMapper?: TypeMapper;

0 commit comments

Comments
 (0)