Cache substitution types (#30775)

This commit is contained in:
Wesley Wigham 2019-04-05 14:37:47 -07:00 committed by GitHub
parent 8684c3bfb8
commit c1f2aba364
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 1 deletions

View File

@ -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;
}

View File

@ -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,