Skip to content

Enable GenerateNamesForShadowedTypeParams for types baselines #55821

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5357,7 +5357,7 @@ export const enum TypeFormatFlags {
None = 0,
NoTruncation = 1 << 0, // Don't truncate typeToString result
WriteArrayAsGenericType = 1 << 1, // Write Array<T> instead T[]
// hole because there's a hole in node builder flags
GenerateNamesForShadowedTypeParams = 1 << 2, // When a type parameter T is shadowing another T, generate a name for it so it can still be referenced
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This API change is to be able to use this flag via the type printing system, since TypeFormatFlags and NodeBuilderFlags overlap intentionally.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if changing this option in baselines is good or not since Quickinfo doesnt use this flag and thats what our type baselines go for?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly I was thinking about whether or not this should be the default for quick info; it too can cause confusion as in: #55820 (comment)

UseStructuralFallback = 1 << 3, // When an alias cannot be named by its symbol, rather than report an error, fallback to a structural printout if possible
// hole because there's a hole in node builder flags
WriteTypeArgumentsOfSignature = 1 << 5, // Write the type arguments instead of type parameters of the signature
Expand Down Expand Up @@ -5388,7 +5388,7 @@ export const enum TypeFormatFlags {
InFirstTypeArgument = 1 << 22, // Writing first type argument of the instantiated type
InTypeAlias = 1 << 23, // Writing type in type alias declaration

NodeBuilderFlagsMask = NoTruncation | WriteArrayAsGenericType | UseStructuralFallback | WriteTypeArgumentsOfSignature |
NodeBuilderFlagsMask = NoTruncation | WriteArrayAsGenericType | GenerateNamesForShadowedTypeParams | UseStructuralFallback | WriteTypeArgumentsOfSignature |
UseFullyQualifiedType | SuppressAnyReturnType | MultilineObjectLiterals | WriteClassExpressionAsTypeLiteral |
UseTypeOfFunction | OmitParameterModifiers | UseAliasDefinedOutsideCurrentScope | AllowUniqueESSymbolType | InTypeAlias |
UseSingleQuotesForStringLiteralType | NoTypeReduction | OmitThisParameter,
Expand Down
5 changes: 3 additions & 2 deletions src/harness/typeWriter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,12 @@ export class TypeWriterWalker {
typeString = (type as ts.IntrinsicType).intrinsicName;
}
else {
typeString = this.checker.typeToString(type, node.parent, ts.TypeFormatFlags.NoTruncation | ts.TypeFormatFlags.AllowUniqueESSymbolType);
const typeFormatFlags = ts.TypeFormatFlags.NoTruncation | ts.TypeFormatFlags.AllowUniqueESSymbolType | ts.TypeFormatFlags.GenerateNamesForShadowedTypeParams;
typeString = this.checker.typeToString(type, node.parent, typeFormatFlags);
if (ts.isIdentifier(node) && ts.isTypeAliasDeclaration(node.parent) && node.parent.name === node && typeString === ts.idText(node)) {
// 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
// the name of the type alias, recreate the type string without reusing the alias name
typeString = this.checker.typeToString(type, node.parent, ts.TypeFormatFlags.NoTruncation | ts.TypeFormatFlags.AllowUniqueESSymbolType | ts.TypeFormatFlags.InTypeAlias);
typeString = this.checker.typeToString(type, node.parent, typeFormatFlags | ts.TypeFormatFlags.InTypeAlias);
}
}
return {
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/1.0lib-noErrors.types
Original file line number Diff line number Diff line change
Expand Up @@ -1886,7 +1886,7 @@ interface Array<T> {
>n : number
}
declare var Array: {
>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>; }
>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>; }

new (arrayLength?: number): any[];
>arrayLength : number
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/anyAssignabilityInInheritance.types
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,13 @@ var r3 = foo3(a); // any
>a : any

declare function foo13(x: <T>(x: T) => T): <T>(x: T) => T;
>foo13 : { (x: <T>(x: T) => T): <T>(x: T) => T; (x: any): any; }
>foo13 : { (x: <T>(x: T) => T): <T_1>(x: T_1) => T_1; (x: any): any; }
>x : <T>(x: T) => T
>x : T
>x : T

declare function foo13(x: any): any;
>foo13 : { (x: <T>(x: T) => T): <T>(x: T) => T; (x: any): any; }
>foo13 : { (x: <T>(x: T) => T): <T_1>(x: T_1) => T_1; (x: any): any; }
>x : any

var r3 = foo3(a); // any
Expand Down
3 changes: 2 additions & 1 deletion tests/baselines/reference/api/typescript.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6887,6 +6887,7 @@ declare namespace ts {
None = 0,
NoTruncation = 1,
WriteArrayAsGenericType = 2,
GenerateNamesForShadowedTypeParams = 4,
UseStructuralFallback = 8,
WriteTypeArgumentsOfSignature = 32,
UseFullyQualifiedType = 64,
Expand All @@ -6906,7 +6907,7 @@ declare namespace ts {
InElementType = 2097152,
InFirstTypeArgument = 4194304,
InTypeAlias = 8388608,
NodeBuilderFlagsMask = 848330091,
NodeBuilderFlagsMask = 848330095,
}
enum SymbolFormatFlags {
None = 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ const debuglog = function() {

return format.apply(null, arguments);
>format.apply(null, arguments) : string
>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; }
>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; }
>format : (f: any, ...args: any[]) => string
>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; }
>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; }
>arguments : IArguments

};
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/arrayDestructuringInSwitch1.types
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ export function evaluate(expression: Expression): boolean {

return operands.every((child) => evaluate(child));
>operands.every((child) => evaluate(child)) : boolean
>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; }
>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; }
>operands : Expression[] | [Expression]
>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; }
>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; }
>(child) => evaluate(child) : (child: Expression) => boolean
>child : Expression
>evaluate(child) : boolean
Expand Down
Loading