Skip to content

Commit b2fc883

Browse files
authored
Enable GenerateNamesForShadowedTypeParams for types baselines (#55821)
1 parent 02006e1 commit b2fc883

File tree

308 files changed

+2549
-2547
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

308 files changed

+2549
-2547
lines changed

src/compiler/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5357,7 +5357,7 @@ export const enum TypeFormatFlags {
53575357
None = 0,
53585358
NoTruncation = 1 << 0, // Don't truncate typeToString result
53595359
WriteArrayAsGenericType = 1 << 1, // Write Array<T> instead T[]
5360-
// hole because there's a hole in node builder flags
5360+
GenerateNamesForShadowedTypeParams = 1 << 2, // When a type parameter T is shadowing another T, generate a name for it so it can still be referenced
53615361
UseStructuralFallback = 1 << 3, // When an alias cannot be named by its symbol, rather than report an error, fallback to a structural printout if possible
53625362
// hole because there's a hole in node builder flags
53635363
WriteTypeArgumentsOfSignature = 1 << 5, // Write the type arguments instead of type parameters of the signature
@@ -5388,7 +5388,7 @@ export const enum TypeFormatFlags {
53885388
InFirstTypeArgument = 1 << 22, // Writing first type argument of the instantiated type
53895389
InTypeAlias = 1 << 23, // Writing type in type alias declaration
53905390

5391-
NodeBuilderFlagsMask = NoTruncation | WriteArrayAsGenericType | UseStructuralFallback | WriteTypeArgumentsOfSignature |
5391+
NodeBuilderFlagsMask = NoTruncation | WriteArrayAsGenericType | GenerateNamesForShadowedTypeParams | UseStructuralFallback | WriteTypeArgumentsOfSignature |
53925392
UseFullyQualifiedType | SuppressAnyReturnType | MultilineObjectLiterals | WriteClassExpressionAsTypeLiteral |
53935393
UseTypeOfFunction | OmitParameterModifiers | UseAliasDefinedOutsideCurrentScope | AllowUniqueESSymbolType | InTypeAlias |
53945394
UseSingleQuotesForStringLiteralType | NoTypeReduction | OmitThisParameter,

src/harness/typeWriter.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,12 @@ export class TypeWriterWalker {
138138
typeString = (type as ts.IntrinsicType).intrinsicName;
139139
}
140140
else {
141-
typeString = this.checker.typeToString(type, node.parent, ts.TypeFormatFlags.NoTruncation | ts.TypeFormatFlags.AllowUniqueESSymbolType);
141+
const typeFormatFlags = ts.TypeFormatFlags.NoTruncation | ts.TypeFormatFlags.AllowUniqueESSymbolType | ts.TypeFormatFlags.GenerateNamesForShadowedTypeParams;
142+
typeString = this.checker.typeToString(type, node.parent, typeFormatFlags);
142143
if (ts.isIdentifier(node) && ts.isTypeAliasDeclaration(node.parent) && node.parent.name === node && typeString === ts.idText(node)) {
143144
// for a complex type alias `type T = ...`, showing "T : T" isn't very helpful for type tests. When the type produced is the same as
144145
// the name of the type alias, recreate the type string without reusing the alias name
145-
typeString = this.checker.typeToString(type, node.parent, ts.TypeFormatFlags.NoTruncation | ts.TypeFormatFlags.AllowUniqueESSymbolType | ts.TypeFormatFlags.InTypeAlias);
146+
typeString = this.checker.typeToString(type, node.parent, typeFormatFlags | ts.TypeFormatFlags.InTypeAlias);
146147
}
147148
}
148149
return {

tests/baselines/reference/1.0lib-noErrors.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1886,7 +1886,7 @@ interface Array<T> {
18861886
>n : number
18871887
}
18881888
declare var Array: {
1889-
>Array : { (arrayLength?: number): any[]; <T>(arrayLength: number): T[]; <T>(...items: T[]): T[]; new (arrayLength?: number): any[]; new <T>(arrayLength: number): T[]; new <T>(...items: T[]): T[]; isArray(arg: any): boolean; prototype: Array<any>; }
1889+
>Array : { (arrayLength?: number): any[]; <T>(arrayLength: number): T[]; <T_1>(...items: T_1[]): T_1[]; new (arrayLength?: number): any[]; new <T_2>(arrayLength: number): T_2[]; new <T_3>(...items: T_3[]): T_3[]; isArray(arg: any): boolean; prototype: Array<any>; }
18901890

18911891
new (arrayLength?: number): any[];
18921892
>arrayLength : number

tests/baselines/reference/anyAssignabilityInInheritance.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,13 @@ var r3 = foo3(a); // any
184184
>a : any
185185

186186
declare function foo13(x: <T>(x: T) => T): <T>(x: T) => T;
187-
>foo13 : { (x: <T>(x: T) => T): <T>(x: T) => T; (x: any): any; }
187+
>foo13 : { (x: <T>(x: T) => T): <T_1>(x: T_1) => T_1; (x: any): any; }
188188
>x : <T>(x: T) => T
189189
>x : T
190190
>x : T
191191

192192
declare function foo13(x: any): any;
193-
>foo13 : { (x: <T>(x: T) => T): <T>(x: T) => T; (x: any): any; }
193+
>foo13 : { (x: <T>(x: T) => T): <T_1>(x: T_1) => T_1; (x: any): any; }
194194
>x : any
195195

196196
var r3 = foo3(a); // any

tests/baselines/reference/api/typescript.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6887,6 +6887,7 @@ declare namespace ts {
68876887
None = 0,
68886888
NoTruncation = 1,
68896889
WriteArrayAsGenericType = 2,
6890+
GenerateNamesForShadowedTypeParams = 4,
68906891
UseStructuralFallback = 8,
68916892
WriteTypeArgumentsOfSignature = 32,
68926893
UseFullyQualifiedType = 64,
@@ -6906,7 +6907,7 @@ declare namespace ts {
69066907
InElementType = 2097152,
69076908
InFirstTypeArgument = 4194304,
69086909
InTypeAlias = 8388608,
6909-
NodeBuilderFlagsMask = 848330091,
6910+
NodeBuilderFlagsMask = 848330095,
69106911
}
69116912
enum SymbolFormatFlags {
69126913
None = 0,

tests/baselines/reference/argumentsReferenceInFunction1_Js.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ const debuglog = function() {
5757

5858
return format.apply(null, arguments);
5959
>format.apply(null, arguments) : string
60-
>format.apply : { <T, R>(this: (this: T) => R, thisArg: T): R; <T, A extends any[], R>(this: (this: T, ...args: A) => R, thisArg: T, args: A): R; }
60+
>format.apply : { <T, R>(this: (this: T) => R, thisArg: T): R; <T_1, A extends any[], R_1>(this: (this: T_1, ...args: A) => R_1, thisArg: T_1, args: A): R_1; }
6161
>format : (f: any, ...args: any[]) => string
62-
>apply : { <T, R>(this: (this: T) => R, thisArg: T): R; <T, A extends any[], R>(this: (this: T, ...args: A) => R, thisArg: T, args: A): R; }
62+
>apply : { <T, R>(this: (this: T) => R, thisArg: T): R; <T_1, A extends any[], R_1>(this: (this: T_1, ...args: A) => R_1, thisArg: T_1, args: A): R_1; }
6363
>arguments : IArguments
6464

6565
};

tests/baselines/reference/arrayDestructuringInSwitch1.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ export function evaluate(expression: Expression): boolean {
3131

3232
return operands.every((child) => evaluate(child));
3333
>operands.every((child) => evaluate(child)) : boolean
34-
>operands.every : { <S extends Expression>(predicate: (value: Expression, index: number, array: Expression[]) => value is S, thisArg?: any): this is S[]; (predicate: (value: Expression, index: number, array: Expression[]) => unknown, thisArg?: any): boolean; } | { <S extends Expression>(predicate: (value: Expression, index: number, array: Expression[]) => value is S, thisArg?: any): this is S[]; (predicate: (value: Expression, index: number, array: Expression[]) => unknown, thisArg?: any): boolean; }
34+
>operands.every : { <S extends Expression>(predicate: (value: Expression, index: number, array: Expression[]) => value is S, thisArg?: any): this is S[]; (predicate: (value: Expression, index: number, array: Expression[]) => unknown, thisArg?: any): boolean; } | { <S_1 extends Expression>(predicate: (value: Expression, index: number, array: Expression[]) => value is S_1, thisArg?: any): this is S_1[]; (predicate: (value: Expression, index: number, array: Expression[]) => unknown, thisArg?: any): boolean; }
3535
>operands : Expression[] | [Expression]
36-
>every : { <S extends Expression>(predicate: (value: Expression, index: number, array: Expression[]) => value is S, thisArg?: any): this is S[]; (predicate: (value: Expression, index: number, array: Expression[]) => unknown, thisArg?: any): boolean; } | { <S extends Expression>(predicate: (value: Expression, index: number, array: Expression[]) => value is S, thisArg?: any): this is S[]; (predicate: (value: Expression, index: number, array: Expression[]) => unknown, thisArg?: any): boolean; }
36+
>every : { <S extends Expression>(predicate: (value: Expression, index: number, array: Expression[]) => value is S, thisArg?: any): this is S[]; (predicate: (value: Expression, index: number, array: Expression[]) => unknown, thisArg?: any): boolean; } | { <S_1 extends Expression>(predicate: (value: Expression, index: number, array: Expression[]) => value is S_1, thisArg?: any): this is S_1[]; (predicate: (value: Expression, index: number, array: Expression[]) => unknown, thisArg?: any): boolean; }
3737
>(child) => evaluate(child) : (child: Expression) => boolean
3838
>child : Expression
3939
>evaluate(child) : boolean

0 commit comments

Comments
 (0)