Skip to content

Commit 6c8bc18

Browse files
authored
Merge pull request #18231 from Microsoft/cacheAnonymousTypes
Improve caching of anonymous types
2 parents b6c708d + 82281d9 commit 6c8bc18

8 files changed

+123
-194
lines changed

src/compiler/checker.ts

Lines changed: 119 additions & 176 deletions
Large diffs are not rendered by default.

src/compiler/types.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3331,13 +3331,12 @@ namespace ts {
33313331
}
33323332

33333333
/* @internal */
3334-
export interface MappedType extends ObjectType {
3334+
export interface MappedType extends AnonymousType {
33353335
declaration: MappedTypeNode;
33363336
typeParameter?: TypeParameter;
33373337
constraintType?: Type;
33383338
templateType?: Type;
33393339
modifiersType?: Type;
3340-
mapper?: TypeMapper; // Instantiation mapper
33413340
}
33423341

33433342
export interface EvolvingArrayType extends ObjectType {
@@ -3469,8 +3468,6 @@ namespace ts {
34693468
/* @internal */
34703469
export interface TypeMapper {
34713470
(t: TypeParameter): Type;
3472-
mappedTypes?: TypeParameter[]; // Types mapped by this mapper
3473-
instantiations?: Type[]; // Cache of instantiations created using this type mapper.
34743471
}
34753472

34763473
export const enum InferencePriority {

src/services/signatureHelp.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,7 @@ namespace ts.SignatureHelp {
372372
if (isTypeParameterList) {
373373
isVariadic = false; // type parameter lists are not variadic
374374
prefixDisplayParts.push(punctuationPart(SyntaxKind.LessThanToken));
375-
// Use `.mapper` to ensure we get the generic type arguments even if this is an instantiated version of the signature.
376-
const typeParameters = candidateSignature.mapper ? candidateSignature.mapper.mappedTypes : candidateSignature.typeParameters;
375+
const typeParameters = (candidateSignature.target || candidateSignature).typeParameters;
377376
signatureHelpParameters = typeParameters && typeParameters.length > 0 ? map(typeParameters, createSignatureHelpParameterForTypeParameter) : emptyArray;
378377
suffixDisplayParts.push(punctuationPart(SyntaxKind.GreaterThanToken));
379378
const parameterParts = mapToDisplayParts(writer =>

tests/baselines/reference/functionConstraintSatisfaction2.errors.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ tests/cases/conformance/types/typeParameters/typeArgumentLists/functionConstrain
2222
Type 'void' is not assignable to type 'string'.
2323
tests/cases/conformance/types/typeParameters/typeArgumentLists/functionConstraintSatisfaction2.ts(38,10): error TS2345: Argument of type 'U' is not assignable to parameter of type '(x: string) => string'.
2424
Type 'T' is not assignable to type '(x: string) => string'.
25-
Type '() => void' is not assignable to type '(x: string) => string'.
26-
Type 'void' is not assignable to type 'string'.
2725

2826

2927
==== tests/cases/conformance/types/typeParameters/typeArgumentLists/functionConstraintSatisfaction2.ts (13 errors) ====
@@ -102,7 +100,5 @@ tests/cases/conformance/types/typeParameters/typeArgumentLists/functionConstrain
102100
~
103101
!!! error TS2345: Argument of type 'U' is not assignable to parameter of type '(x: string) => string'.
104102
!!! error TS2345: Type 'T' is not assignable to type '(x: string) => string'.
105-
!!! error TS2345: Type '() => void' is not assignable to type '(x: string) => string'.
106-
!!! error TS2345: Type 'void' is not assignable to type 'string'.
107103
}
108104

tests/baselines/reference/limitDeepInstantiations.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
tests/cases/compiler/limitDeepInstantiations.ts(3,35): error TS2550: Generic type instantiation is excessively deep and possibly infinite.
1+
tests/cases/compiler/limitDeepInstantiations.ts(3,35): error TS2502: '"true"' is referenced directly or indirectly in its own type annotation.
22
tests/cases/compiler/limitDeepInstantiations.ts(5,13): error TS2344: Type '"false"' does not satisfy the constraint '"true"'.
33

44

@@ -7,7 +7,7 @@ tests/cases/compiler/limitDeepInstantiations.ts(5,13): error TS2344: Type '"fals
77

88
type Foo<T extends "true", B> = { "true": Foo<T, Foo<T, B>> }[T];
99
~~~~~~~~~~~~~~~~~~~~~~~~~
10-
!!! error TS2550: Generic type instantiation is excessively deep and possibly infinite.
10+
!!! error TS2502: '"true"' is referenced directly or indirectly in its own type annotation.
1111
let f1: Foo<"true", {}>;
1212
let f2: Foo<"false", {}>;
1313
~~~~~~~

tests/baselines/reference/promisePermutations.errors.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ tests/cases/compiler/promisePermutations.ts(134,19): error TS2345: Argument of t
4545
tests/cases/compiler/promisePermutations.ts(137,33): error TS2345: Argument of type '(x: any) => IPromise<string>' is not assignable to parameter of type '(error: any) => IPromise<number>'.
4646
Type 'IPromise<string>' is not assignable to type 'IPromise<number>'.
4747
tests/cases/compiler/promisePermutations.ts(144,35): error TS2345: Argument of type '(x: any) => IPromise<string>' is not assignable to parameter of type '(error: any) => IPromise<number>'.
48-
Type 'IPromise<string>' is not assignable to type 'IPromise<number>'.
4948
tests/cases/compiler/promisePermutations.ts(152,36): error TS2345: Argument of type '(x: any) => IPromise<string>' is not assignable to parameter of type '(error: any) => Promise<number>'.
5049
Type 'IPromise<string>' is not assignable to type 'Promise<number>'.
5150
Property 'catch' is missing in type 'IPromise<string>'.
@@ -286,7 +285,6 @@ tests/cases/compiler/promisePermutations.ts(160,21): error TS2345: Argument of t
286285
var r10d = r10.then(testFunction, sIPromise, nIPromise); // ok
287286
~~~~~~~~~
288287
!!! error TS2345: Argument of type '(x: any) => IPromise<string>' is not assignable to parameter of type '(error: any) => IPromise<number>'.
289-
!!! error TS2345: Type 'IPromise<string>' is not assignable to type 'IPromise<number>'.
290288
var r10e = r10.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok
291289
var s10 = testFunction10P(x => x);
292290
var s10a = s10.then(testFunction10, testFunction10, testFunction10); // ok

tests/baselines/reference/promisePermutations2.errors.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ tests/cases/compiler/promisePermutations2.ts(133,19): error TS2345: Argument of
4545
tests/cases/compiler/promisePermutations2.ts(136,33): error TS2345: Argument of type '(x: any) => IPromise<string>' is not assignable to parameter of type '(error: any) => IPromise<number>'.
4646
Type 'IPromise<string>' is not assignable to type 'IPromise<number>'.
4747
tests/cases/compiler/promisePermutations2.ts(143,35): error TS2345: Argument of type '(x: any) => IPromise<string>' is not assignable to parameter of type '(error: any) => IPromise<number>'.
48-
Type 'IPromise<string>' is not assignable to type 'IPromise<number>'.
4948
tests/cases/compiler/promisePermutations2.ts(151,36): error TS2345: Argument of type '(x: any) => IPromise<string>' is not assignable to parameter of type '(error: any) => Promise<number>'.
5049
Type 'IPromise<string>' is not assignable to type 'Promise<number>'.
5150
Property 'catch' is missing in type 'IPromise<string>'.
@@ -285,7 +284,6 @@ tests/cases/compiler/promisePermutations2.ts(159,21): error TS2345: Argument of
285284
var r10d = r10.then(testFunction, sIPromise, nIPromise); // error
286285
~~~~~~~~~
287286
!!! error TS2345: Argument of type '(x: any) => IPromise<string>' is not assignable to parameter of type '(error: any) => IPromise<number>'.
288-
!!! error TS2345: Type 'IPromise<string>' is not assignable to type 'IPromise<number>'.
289287
var r10e = r10.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok
290288
var s10 = testFunction10P(x => x);
291289
var s10a = s10.then(testFunction10, testFunction10, testFunction10); // ok

tests/baselines/reference/promisePermutations3.errors.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ tests/cases/compiler/promisePermutations3.ts(133,19): error TS2345: Argument of
4848
tests/cases/compiler/promisePermutations3.ts(136,33): error TS2345: Argument of type '(x: any) => IPromise<string>' is not assignable to parameter of type '(error: any) => IPromise<number>'.
4949
Type 'IPromise<string>' is not assignable to type 'IPromise<number>'.
5050
tests/cases/compiler/promisePermutations3.ts(143,35): error TS2345: Argument of type '(x: any) => IPromise<string>' is not assignable to parameter of type '(error: any) => IPromise<number>'.
51-
Type 'IPromise<string>' is not assignable to type 'IPromise<number>'.
5251
tests/cases/compiler/promisePermutations3.ts(151,36): error TS2345: Argument of type '(x: any) => IPromise<string>' is not assignable to parameter of type '(error: any) => Promise<number>'.
5352
Type 'IPromise<string>' is not assignable to type 'Promise<number>'.
5453
Property 'catch' is missing in type 'IPromise<string>'.
@@ -295,7 +294,6 @@ tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of
295294
var r10d = r10.then(testFunction, sIPromise, nIPromise); // error
296295
~~~~~~~~~
297296
!!! error TS2345: Argument of type '(x: any) => IPromise<string>' is not assignable to parameter of type '(error: any) => IPromise<number>'.
298-
!!! error TS2345: Type 'IPromise<string>' is not assignable to type 'IPromise<number>'.
299297
var r10e = r10.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok
300298
var s10 = testFunction10P(x => x);
301299
var s10a = s10.then(testFunction10, testFunction10, testFunction10); // ok

0 commit comments

Comments
 (0)