mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-12-12 20:25:48 -06:00
Cache substitution types (#30775)
This commit is contained in:
parent
8684c3bfb8
commit
c1f2aba364
@ -392,6 +392,7 @@ namespace ts {
|
||||
const literalTypes = createMap<LiteralType>();
|
||||
const indexedAccessTypes = createMap<IndexedAccessType>();
|
||||
const conditionalTypes = createMap<Type>();
|
||||
const substitutionTypes = createMap<SubstitutionType>();
|
||||
const evolvingArrayTypes: EvolvingArrayType[] = [];
|
||||
const undefinedProperties = createMap<Symbol>() as UnderscoreEscapedMap<Symbol>;
|
||||
|
||||
@ -8914,9 +8915,15 @@ namespace ts {
|
||||
if (substitute.flags & TypeFlags.AnyOrUnknown) {
|
||||
return typeVariable;
|
||||
}
|
||||
const id = `${getTypeId(typeVariable)}>${getTypeId(substitute)}`;
|
||||
const cached = substitutionTypes.get(id);
|
||||
if (cached) {
|
||||
return cached;
|
||||
}
|
||||
const result = <SubstitutionType>createType(TypeFlags.Substitution);
|
||||
result.typeVariable = typeVariable;
|
||||
result.substitute = substitute;
|
||||
substitutionTypes.set(id, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@ -31,7 +31,7 @@ class A {
|
||||
>z : A[]
|
||||
|
||||
whereRelated< // Works // Type is same as A1, but is not assignable to type A
|
||||
>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
|
||||
>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
|
||||
|
||||
RF extends RelationFields = RelationFields,
|
||||
N extends Name = Name,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user