Skip to content

Commit b975dfa

Browse files
authored
Write more useful types in .types test outputs (#48578)
1 parent 4d2fb54 commit b975dfa

File tree

428 files changed

+1197
-1189
lines changed

Some content is hidden

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

428 files changed

+1197
-1189
lines changed

src/harness/typeWriter.ts

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -115,31 +115,39 @@ namespace Harness {
115115
// let type = this.checker.getTypeAtLocation(node);
116116
let type = ts.isExpressionWithTypeArgumentsInClassExtendsClause(node.parent) ? this.checker.getTypeAtLocation(node.parent) : undefined;
117117
if (!type || type.flags & ts.TypeFlags.Any) type = this.checker.getTypeAtLocation(node);
118-
const typeString =
119-
// Distinguish `errorType`s from `any`s; but only if the file has no errors.
120-
// Additionally,
121-
// * the LHS of a qualified name
122-
// * a binding pattern name
123-
// * labels
124-
// * the "global" in "declare global"
125-
// * the "target" in "new.target"
126-
// * names in import statements
127-
// * type-only names in export statements
128-
// * and intrinsic jsx tag names
129-
// return `error`s via `getTypeAtLocation`
130-
// But this is generally expected, so we don't call those out, either
131-
(!this.hadErrorBaseline &&
132-
type.flags & ts.TypeFlags.Any &&
133-
!ts.isBindingElement(node.parent) &&
134-
!ts.isPropertyAccessOrQualifiedName(node.parent) &&
135-
!ts.isLabelName(node) &&
136-
!(ts.isModuleDeclaration(node.parent) && ts.isGlobalScopeAugmentation(node.parent)) &&
137-
!ts.isMetaProperty(node.parent) &&
138-
!this.isImportStatementName(node) &&
139-
!this.isExportStatementName(node) &&
140-
!this.isIntrinsicJsxTag(node)) ?
141-
(type as ts.IntrinsicType).intrinsicName :
142-
this.checker.typeToString(type, node.parent, ts.TypeFormatFlags.NoTruncation | ts.TypeFormatFlags.AllowUniqueESSymbolType);
118+
// Distinguish `errorType`s from `any`s; but only if the file has no errors.
119+
// Additionally,
120+
// * the LHS of a qualified name
121+
// * a binding pattern name
122+
// * labels
123+
// * the "global" in "declare global"
124+
// * the "target" in "new.target"
125+
// * names in import statements
126+
// * type-only names in export statements
127+
// * and intrinsic jsx tag names
128+
// return `error`s via `getTypeAtLocation`
129+
// But this is generally expected, so we don't call those out, either
130+
let typeString: string;
131+
if (!this.hadErrorBaseline &&
132+
type.flags & ts.TypeFlags.Any &&
133+
!ts.isBindingElement(node.parent) &&
134+
!ts.isPropertyAccessOrQualifiedName(node.parent) &&
135+
!ts.isLabelName(node) &&
136+
!(ts.isModuleDeclaration(node.parent) && ts.isGlobalScopeAugmentation(node.parent)) &&
137+
!ts.isMetaProperty(node.parent) &&
138+
!this.isImportStatementName(node) &&
139+
!this.isExportStatementName(node) &&
140+
!this.isIntrinsicJsxTag(node)) {
141+
typeString = (type as ts.IntrinsicType).intrinsicName;
142+
}
143+
else {
144+
typeString = this.checker.typeToString(type, node.parent, ts.TypeFormatFlags.NoTruncation | ts.TypeFormatFlags.AllowUniqueESSymbolType);
145+
if (ts.isIdentifier(node) && ts.isTypeAliasDeclaration(node.parent) && node.parent.name === node && typeString === ts.idText(node)) {
146+
// 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
147+
// the name of the type alias, recreate the type string without reusing the alias name
148+
typeString = this.checker.typeToString(type, node.parent, ts.TypeFormatFlags.NoTruncation | ts.TypeFormatFlags.AllowUniqueESSymbolType | ts.TypeFormatFlags.InTypeAlias);
149+
}
150+
}
143151
return {
144152
line: lineAndCharacter.line,
145153
syntaxKind: node.kind,

tests/baselines/reference/DeclarationErrorsNoEmitOnError.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
=== tests/cases/compiler/DeclarationErrorsNoEmitOnError.ts ===
22
type T = { x : number }
3-
>T : T
3+
>T : { x: number; }
44
>x : number
55

66
export interface I {

tests/baselines/reference/abstractClassUnionInstantiation.types

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ abstract class AbstractB { b: string; }
1414
>b : string
1515

1616
type Abstracts = typeof AbstractA | typeof AbstractB;
17-
>Abstracts : Abstracts
17+
>Abstracts : typeof AbstractA | typeof AbstractB
1818
>AbstractA : typeof AbstractA
1919
>AbstractB : typeof AbstractB
2020

2121
type Concretes = typeof ConcreteA | typeof ConcreteB;
22-
>Concretes : Concretes
22+
>Concretes : typeof ConcreteA | typeof ConcreteB
2323
>ConcreteA : typeof ConcreteA
2424
>ConcreteB : typeof ConcreteB
2525

2626
type ConcretesOrAbstracts = Concretes | Abstracts;
27-
>ConcretesOrAbstracts : ConcretesOrAbstracts
27+
>ConcretesOrAbstracts : Abstracts | Concretes
2828

2929
declare const cls1: ConcretesOrAbstracts;
3030
>cls1 : ConcretesOrAbstracts

tests/baselines/reference/accessorBodyInTypeContext.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
=== tests/cases/compiler/accessorBodyInTypeContext.ts ===
22
type A = {
3-
>A : A
3+
>A : { readonly foo: number; }
44

55
get foo() { return 0 }
66
>foo : number
@@ -9,7 +9,7 @@ type A = {
99
};
1010

1111
type B = {
12-
>B : B
12+
>B : { foo: any; }
1313

1414
set foo(v: any) { }
1515
>foo : any

tests/baselines/reference/aliasOfGenericFunctionWithRestBehavedSameAsUnaliased.types

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ type ExtendedMapper<HandledInputT, OutputT, ArgsT extends any[]> = (name : strin
88
>args : ArgsT
99

1010
type a = ExtendedMapper<any, any, [any]>;
11-
>a : a
11+
>a : (name: string, mixed: any, args_0: any) => any
1212

1313
type b = ExtendedMapper<any, any, any[]>;
14-
>b : b
14+
>b : (name: string, mixed: any, ...args: any[]) => any
1515

1616
type test = a extends b ? "y" : "n"
1717
>test : "y"
@@ -32,10 +32,10 @@ type ExtendedMapper1<HandledInputT, OutputT, ArgsT extends any[]> = (
3232
);
3333

3434
type a1 = ExtendedMapper1<any, any, [any]>;
35-
>a1 : a1
35+
>a1 : (name: string, mixed: any, args_0: any) => any
3636

3737
type b1 = ExtendedMapper1<any, any, any[]>;
38-
>b1 : b1
38+
>b1 : (name: string, mixed: any, ...args: any[]) => any
3939

4040
type test1 = a1 extends b1 ? "y" : "n"
4141
>test1 : "y"
@@ -56,10 +56,10 @@ type ExtendedMapper2<HandledInputT, OutputT, ArgsT extends any[]> = (
5656
);
5757

5858
type a2 = ExtendedMapper2<any, any, [any]>;
59-
>a2 : a2
59+
>a2 : (name: string, mixed: any, args_0: any) => any
6060

6161
type b2 = ExtendedMapper2<any, any, any[]>;
62-
>b2 : b2
62+
>b2 : (name: string, mixed: any, ...args: any[]) => any
6363

6464
type test2 = a2 extends b2 ? "y" : "n"
6565
>test2 : "y"
@@ -69,13 +69,13 @@ let check2: test2 = "y";
6969
>"y" : "y"
7070

7171
type a3 = (name: string, mixed: any, args_0: any) => any
72-
>a3 : a3
72+
>a3 : (name: string, mixed: any, args_0: any) => any
7373
>name : string
7474
>mixed : any
7575
>args_0 : any
7676

7777
type b3 = (name: string, mixed: any, ...args: any[]) => any
78-
>b3 : b3
78+
>b3 : (name: string, mixed: any, ...args: any[]) => any
7979
>name : string
8080
>mixed : any
8181
>args : any[]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
=== tests/cases/compiler/anyMappedTypesError.ts ===
22
type Foo = {[P in "bar"]};
3-
>Foo : Foo
3+
>Foo : { bar: any; }
44

tests/baselines/reference/argumentsAsPropertyName.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
=== tests/cases/compiler/argumentsAsPropertyName.ts ===
22
// target: es5
33
type MyType = {
4-
>MyType : MyType
4+
>MyType : { arguments: Array<string>; }
55

66
arguments: Array<string>
77
>arguments : string[]

tests/baselines/reference/arrayDestructuringInSwitch1.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
=== tests/cases/compiler/arrayDestructuringInSwitch1.ts ===
22
export type Expression = BooleanLogicExpression | 'true' | 'false';
3-
>Expression : Expression
3+
>Expression : BooleanLogicExpression | "true" | "false"
44

55
export type BooleanLogicExpression = ['and', ...Expression[]] | ['not', Expression];
6-
>BooleanLogicExpression : BooleanLogicExpression
6+
>BooleanLogicExpression : ["and", ...Expression[]] | ["not", Expression]
77

88
export function evaluate(expression: Expression): boolean {
99
>evaluate : (expression: Expression) => boolean

tests/baselines/reference/arrayDestructuringInSwitch2.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
=== tests/cases/compiler/arrayDestructuringInSwitch2.ts ===
22
type X = { kind: "a", a: [1] } | { kind: "b", a: [] }
3-
>X : X
3+
>X : { kind: "a"; a: [1]; } | { kind: "b"; a: []; }
44
>kind : "a"
55
>a : [1]
66
>kind : "b"

tests/baselines/reference/assertionFunctionsCanNarrowByDiscriminant.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ interface Dog {
1818
}
1919

2020
type Animal = Cat | Dog;
21-
>Animal : Animal
21+
>Animal : Cat | Dog
2222

2323
declare function assertEqual<T>(value: any, type: T): asserts value is T;
2424
>assertEqual : <T>(value: any, type: T) => asserts value is T

0 commit comments

Comments
 (0)