Skip to content

Commit 6024f74

Browse files
committed
Cache substitution types (microsoft#30775)
1 parent 7eb4739 commit 6024f74

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/compiler/checker.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@ namespace ts {
392392
const literalTypes = createMap<LiteralType>();
393393
const indexedAccessTypes = createMap<IndexedAccessType>();
394394
const conditionalTypes = createMap<Type>();
395+
const substitutionTypes = createMap<SubstitutionType>();
395396
const evolvingArrayTypes: EvolvingArrayType[] = [];
396397
const undefinedProperties = createMap<Symbol>() as UnderscoreEscapedMap<Symbol>;
397398

@@ -8870,9 +8871,15 @@ namespace ts {
88708871
if (substitute.flags & TypeFlags.AnyOrUnknown) {
88718872
return typeVariable;
88728873
}
8874+
const id = `${getTypeId(typeVariable)}>${getTypeId(substitute)}`;
8875+
const cached = substitutionTypes.get(id);
8876+
if (cached) {
8877+
return cached;
8878+
}
88738879
const result = <SubstitutionType>createType(TypeFlags.Substitution);
88748880
result.typeVariable = typeVariable;
88758881
result.substitute = substitute;
8882+
substitutionTypes.set(id, result);
88768883
return result;
88778884
}
88788885

tests/baselines/reference/inlinedAliasAssignableToConstraintSameAsAlias.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class A {
3131
>z : A[]
3232

3333
whereRelated< // Works // Type is same as A1, but is not assignable to type A
34-
>whereRelated : <RF extends RelationFields = RelationFields, N extends "x" | "y" | "z" = "x" | "y" | "z", A1 extends A = RF[N] extends A[] ? RF[N][0] : never, A2 extends A = ShouldA<RF, N>>() => number
34+
>whereRelated : <RF extends RelationFields = RelationFields, N extends "x" | "y" | "z" = "x" | "y" | "z", A1 extends A = RF[N] extends A[] ? RF[N][0] : never, A2 extends A = RF[N] extends A[] ? RF[N][0] : never>() => number
3535

3636
RF extends RelationFields = RelationFields,
3737
N extends Name = Name,

0 commit comments

Comments
 (0)