Skip to content

Commit fece7f1

Browse files
authored
Preserve type nodes which resolve to errors in declaration emit output (#58475)
1 parent bc14459 commit fece7f1

File tree

71 files changed

+1260
-1245
lines changed

Some content is hidden

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

71 files changed

+1260
-1245
lines changed

src/compiler/checker.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -8160,7 +8160,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
81608160
function serializeTypeForDeclaration(context: NodeBuilderContext, declaration: Declaration | undefined, type: Type, symbol: Symbol) {
81618161
const addUndefined = declaration && (isParameter(declaration) || isJSDocParameterTag(declaration)) && requiresAddingImplicitUndefined(declaration);
81628162
const enclosingDeclaration = context.enclosingDeclaration;
8163-
if (!isErrorType(type) && enclosingDeclaration) {
8163+
if (enclosingDeclaration && (!isErrorType(type) || (context.flags & NodeBuilderFlags.AllowUnresolvedNames))) {
81648164
const declWithExistingAnnotation = declaration && getNonlocalEffectiveTypeAnnotationNode(declaration)
81658165
? declaration
81668166
: getDeclarationWithTypeAnnotation(symbol, getEnclosingDeclarationIgnoringFakeScope(enclosingDeclaration));
@@ -8460,7 +8460,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
84608460
);
84618461
}
84628462
if (isNamedDeclaration(node) && node.name.kind === SyntaxKind.ComputedPropertyName && !isLateBindableName(node.name)) {
8463-
if (!(context.flags & NodeBuilderFlags.AllowUnresolvedComputedNames && hasDynamicName(node) && isEntityNameExpression(node.name.expression) && checkComputedPropertyName(node.name).flags & TypeFlags.Any)) {
8463+
if (!(context.flags & NodeBuilderFlags.AllowUnresolvedNames && hasDynamicName(node) && isEntityNameExpression(node.name.expression) && checkComputedPropertyName(node.name).flags & TypeFlags.Any)) {
84648464
return undefined;
84658465
}
84668466
}

src/compiler/transformers/declarations.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ const declarationEmitNodeBuilderFlags = NodeBuilderFlags.MultilineObjectLiterals
233233
NodeBuilderFlags.UseTypeOfFunction |
234234
NodeBuilderFlags.UseStructuralFallback |
235235
NodeBuilderFlags.AllowEmptyTuple |
236-
NodeBuilderFlags.AllowUnresolvedComputedNames |
236+
NodeBuilderFlags.AllowUnresolvedNames |
237237
NodeBuilderFlags.GenerateNamesForShadowedTypeParams |
238238
NodeBuilderFlags.NoTruncation;
239239

src/compiler/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5432,7 +5432,7 @@ export const enum NodeBuilderFlags {
54325432
// Errors (cont.)
54335433
AllowNodeModulesRelativePaths = 1 << 26,
54345434
/** @internal */ DoNotIncludeSymbolChain = 1 << 27, // Skip looking up and printing an accessible symbol chain
5435-
/** @internal */ AllowUnresolvedComputedNames = 1 << 32,
5435+
/** @internal */ AllowUnresolvedNames = 1 << 32,
54365436

54375437
IgnoreErrors = AllowThisInObjectLiteral | AllowQualifiedNameInPlaceOfIdentifier | AllowAnonymousIdentifier | AllowEmptyUnionOrIntersection | AllowEmptyTuple | AllowEmptyIndexInfoType | AllowNodeModulesRelativePaths,
54385438

tests/baselines/reference/ArrowFunction1.types

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
=== ArrowFunction1.ts ===
44
var v = (a: ) => {
55
>v : (a: any) => void
6-
> : ^ ^^^^^^^^^^^^^^
6+
> : ^ ^^ ^^^^^^^^^
77
>(a: ) => { } : (a: any) => void
8-
> : ^ ^^^^^^^^^^^^^^
8+
> : ^ ^^ ^^^^^^^^^
99
>a : any
1010
> : ^^^
1111

tests/baselines/reference/ClassAndModuleThatMergeWithModuleMemberThatUsesClassTypeParameter.types

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module clodule1 {
2222

2323
function f(x: T) { }
2424
>f : (x: T) => void
25-
> : ^ ^^^^^^^^^^^^
25+
> : ^ ^^ ^^^^^^^^^
2626
>x : T
2727
> : ^
2828
}

tests/baselines/reference/arguments.types

+6-6
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,16 @@ function f() {
3838

3939
interface I {
4040
method(args: typeof arguments): void;
41-
>method : (args: any) => void
42-
> : ^ ^^^^^^^^^^
41+
>method : (args: typeof arguments) => void
42+
> : ^ ^^ ^^^^^
4343
>args : any
4444
> : ^^^
4545
>arguments : any
4646
> : ^^^
4747

4848
fn: (args: typeof arguments) => void;
49-
>fn : (args: any) => void
50-
> : ^ ^^^^^^^^^^
49+
>fn : (args: typeof arguments) => void
50+
> : ^ ^^ ^^^^^
5151
>args : any
5252
> : ^^^
5353
>arguments : any
@@ -66,8 +66,8 @@ interface I {
6666
> : ^^^
6767

6868
construct: new (args: typeof arguments) => void;
69-
>construct : new (args: any) => void
70-
> : ^^^^^ ^^^^^^^^^^
69+
>construct : new (args: typeof arguments) => void
70+
> : ^^^^^ ^^ ^^^^^
7171
>args : any
7272
> : ^^^
7373
>arguments : any

tests/baselines/reference/arrayReferenceWithoutTypeArgs.types

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ class X {
66
> : ^
77

88
public f(a: Array) { }
9-
>f : (a: any) => void
10-
> : ^ ^^^^^^^^^^^^^^
9+
>f : (a: Array) => void
10+
> : ^ ^^ ^^^^^^^^^
1111
>a : any
1212
> : ^^^
1313
}

tests/baselines/reference/badExternalModuleReference.types

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import a1 = require("garbage");
77

88
export declare var a: {
99
>a : { (): a1.connectExport; test1: a1.connectModule; }
10-
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^
1111

1212
test1: a1.connectModule;
1313
>test1 : a1.connectModule

tests/baselines/reference/circularBaseTypes.types

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ type M3 = M2[keyof M2]; // Error
1515
> : ^^^
1616

1717
function f(m: M3) {
18-
>f : (m: any) => any
19-
> : ^ ^^^^^^^^^^^^^
18+
>f : (m: M3) => any
19+
> : ^ ^^ ^^^^^^^^
2020
>m : any
2121
> : ^^^
2222

tests/baselines/reference/errorsInGenericTypeReference.types

+12-12
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ class testClass2<T> {
4545
}
4646
var tc2 = new testClass2<{ x: V }>(); // error: could not find symbol V
4747
>tc2 : testClass2<{ x: V; }>
48-
> : ^^^^^^^^^^^^^^^^^^^^^
48+
> : ^^^^^^^^^^^^^^^^ ^^^^
4949
>new testClass2<{ x: V }>() : testClass2<{ x: V; }>
50-
> : ^^^^^^^^^^^^^^^^^^^^^
50+
> : ^^^^^^^^^^^^^^^^ ^^^^
5151
>testClass2 : typeof testClass2
5252
> : ^^^^^^^^^^^^^^^^^
5353
>x : V
@@ -73,15 +73,15 @@ class testClass3 {
7373

7474
set a(value: Foo<{ x: V }>) { } // error: could not find symbol V
7575
>a : Foo<{ x: V; }>
76-
> : ^^^^^^^^^^^^^^
76+
> : ^^^^^^^^^ ^^^^
7777
>value : Foo<{ x: V; }>
78-
> : ^^^^^^^^^^^^^^
78+
> : ^^^^^^^^^ ^^^^
7979
>x : V
8080
> : ^
8181

8282
property: Foo<{ x: V }>; // error: could not find symbol V
8383
>property : Foo<{ x: V; }>
84-
> : ^^^^^^^^^^^^^^
84+
> : ^^^^^^^^^ ^^^^
8585
>x : V
8686
> : ^
8787
}
@@ -100,15 +100,15 @@ function testFunction2(p: Foo<{ x: V }>) { }// error: could not find symbol V
100100
>testFunction2 : (p: Foo<{ x: V; }>) => void
101101
> : ^ ^^ ^^^^^^^^^
102102
>p : Foo<{ x: V; }>
103-
> : ^^^^^^^^^^^^^^
103+
> : ^^^^^^^^^ ^^^^
104104
>x : V
105105
> : ^
106106

107107

108108
// in var type annotation
109109
var f: Foo<{ x: V }>; // error: could not find symbol V
110110
>f : Foo<{ x: V; }>
111-
> : ^^^^^^^^^^^^^^
111+
> : ^^^^^^^^^ ^^^^
112112
>x : V
113113
> : ^
114114

@@ -130,7 +130,7 @@ class testClass6<T> {
130130

131131
method<M extends { x: V }>(): void { } // error: could not find symbol V
132132
>method : <M extends { x: V; }>() => void
133-
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
133+
> : ^^^^^^^^^^^^^^^^ ^^^^^^^^^^
134134
>x : V
135135
> : ^
136136
}
@@ -149,7 +149,7 @@ class testClass7 extends Foo<{ x: V }> { } // error: could not find symbol V
149149
>testClass7 : testClass7
150150
> : ^^^^^^^^^^
151151
>Foo : Foo<{ x: V; }>
152-
> : ^^^^^^^^^^^^^^
152+
> : ^^^^^^^^^ ^^^^
153153
>x : V
154154
> : ^
155155

@@ -166,7 +166,7 @@ class testClass8 implements IFoo<{ x: V }> { } // error: could not find symbol V
166166
interface testInterface2 {
167167
new (a: Foo<{ x: V }>): Foo<{ x: V }>; //2x: error: could not find symbol V
168168
>a : Foo<{ x: V; }>
169-
> : ^^^^^^^^^^^^^^
169+
> : ^^^^^^^^^ ^^^^
170170
>x : V
171171
> : ^
172172
>x : V
@@ -182,15 +182,15 @@ interface testInterface2 {
182182
>method : (a: Foo<{ x: V; }>) => Foo<{ x: V; }>
183183
> : ^ ^^ ^^^^^
184184
>a : Foo<{ x: V; }>
185-
> : ^^^^^^^^^^^^^^
185+
> : ^^^^^^^^^ ^^^^
186186
>x : V
187187
> : ^
188188
>x : V
189189
> : ^
190190

191191
property: Foo<{ x: V }>; // error: could not find symbol V
192192
>property : Foo<{ x: V; }>
193-
> : ^^^^^^^^^^^^^^
193+
> : ^^^^^^^^^ ^^^^
194194
>x : V
195195
> : ^
196196
}

tests/baselines/reference/experimentalDecoratorMetadataUnresolvedTypeObjectInEmit.types

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Foo {
1717

1818
f(@decorate user: A.B.C.D.E): void {}
1919
>f : (user: A.B.C.D.E) => void
20-
> : ^ ^^^^^^^^^^^^^^^^
20+
> : ^ ^^ ^^^^^
2121
>decorate : any
2222
> : ^^^
2323
>user : A.B.C.D.E

tests/baselines/reference/extendArray.types

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ declare module _Core {
3636
>collect : (fn: (e: _element) => _element[]) => any[]
3737
> : ^ ^^ ^^^^^
3838
>fn : (e: _element) => _element[]
39-
> : ^ ^^^^^^^^^^^^^^^
39+
> : ^ ^^ ^^^^^
4040
>e : _element
4141
> : ^^^^^^^^
4242
}

tests/baselines/reference/genericCallWithGenericSignatureArguments2.types

+1-1
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ module TU {
435435
>x : T
436436
> : ^
437437
>b : (x: U) => U
438-
> : ^ ^^^^^^^^^
438+
> : ^ ^^ ^^^^^^
439439
>x : U
440440
> : ^
441441

tests/baselines/reference/genericClassWithStaticsUsingTypeArguments.types

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ class Foo<T> {
88

99
static a = (n: T) => { };
1010
>a : (n: T) => void
11-
> : ^ ^^^^^^^^^^^^
11+
> : ^ ^^ ^^^^^^^^^
1212
>(n: T) => { } : (n: T) => void
13-
> : ^ ^^^^^^^^^^^^
13+
> : ^ ^^ ^^^^^^^^^
1414
>n : T
1515
> : ^
1616

@@ -34,9 +34,9 @@ class Foo<T> {
3434
>((x: T) => x || undefined)(null) : any
3535
> : ^^^
3636
>((x: T) => x || undefined) : (x: T) => any
37-
> : ^ ^^^^^^^^^^^
37+
> : ^ ^^ ^^^^^^^^
3838
>(x: T) => x || undefined : (x: T) => any
39-
> : ^ ^^^^^^^^^^^
39+
> : ^ ^^ ^^^^^^^^
4040
>x : T
4141
> : ^
4242
>x || undefined : any
@@ -48,9 +48,9 @@ class Foo<T> {
4848

4949
static e = function (x: T) { return null; }
5050
>e : (x: T) => any
51-
> : ^ ^^^^^^^^^^^
51+
> : ^ ^^ ^^^^^^^^
5252
>function (x: T) { return null; } : (x: T) => any
53-
> : ^ ^^^^^^^^^^^
53+
> : ^ ^^ ^^^^^^^^
5454
>x : T
5555
> : ^
5656

tests/baselines/reference/genericLambaArgWithoutTypeArguments.types

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ foo((arg: Foo) => { return arg.x; });
1919
> : ^^^
2020
>foo : (a: any) => any
2121
> : ^ ^^^^^^^^^^^^^
22-
>(arg: Foo) => { return arg.x; } : (arg: any) => any
23-
> : ^ ^^^^^^^^^^^^^
22+
>(arg: Foo) => { return arg.x; } : (arg: Foo) => any
23+
> : ^ ^^ ^^^^^^^^
2424
>arg : any
2525
> : ^^^
2626
>arg.x : any

tests/baselines/reference/genericRecursiveImplicitConstructorErrors3.types

+8-8
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ module TypeScript {
4545
> : ^^^
4646

4747
public toString<A,B,C>(scopeSymbol?: PullSymbol, useConstraintInName?: boolean) {
48-
>toString : <A, B, C>(scopeSymbol?: any, useConstraintInName?: boolean) => any
49-
> : ^^^^^^^^^^ ^^^^^^^^ ^^^ ^^^^^^^^
48+
>toString : <A, B, C>(scopeSymbol?: PullSymbol, useConstraintInName?: boolean) => any
49+
> : ^^^^^^^^^^ ^^^ ^^ ^^^ ^^^^^^^^
5050
>scopeSymbol : any
5151
> : ^^^
5252
>useConstraintInName : boolean
@@ -61,12 +61,12 @@ module TypeScript {
6161
> : ^^^
6262
>this.getScopedNameEx(scopeSymbol, useConstraintInName) : any
6363
> : ^^^
64-
>this.getScopedNameEx : <A_1, B_1, C_1>(scopeSymbol?: any, useConstraintInName?: boolean, getPrettyTypeName?: boolean, getTypeParamMarkerInfo?: boolean) => any
65-
> : ^^^^^^^^^^^^^^^^ ^^^^^^^^ ^^^ ^^ ^^^ ^^ ^^^ ^^^^^^^^
64+
>this.getScopedNameEx : <A_1, B_1, C_1>(scopeSymbol?: PullSymbol, useConstraintInName?: boolean, getPrettyTypeName?: boolean, getTypeParamMarkerInfo?: boolean) => any
65+
> : ^^^^^^^^^^^^^^^^ ^^^ ^^ ^^^ ^^ ^^^ ^^ ^^^ ^^^^^^^^
6666
>this : this
6767
> : ^^^^
68-
>getScopedNameEx : <A_1, B_1, C_1>(scopeSymbol?: any, useConstraintInName?: boolean, getPrettyTypeName?: boolean, getTypeParamMarkerInfo?: boolean) => any
69-
> : ^^^^^^^^^^^^^^^^ ^^^^^^^^ ^^^ ^^ ^^^ ^^ ^^^ ^^^^^^^^
68+
>getScopedNameEx : <A_1, B_1, C_1>(scopeSymbol?: PullSymbol, useConstraintInName?: boolean, getPrettyTypeName?: boolean, getTypeParamMarkerInfo?: boolean) => any
69+
> : ^^^^^^^^^^^^^^^^ ^^^ ^^ ^^^ ^^ ^^^ ^^ ^^^ ^^^^^^^^
7070
>scopeSymbol : any
7171
> : ^^^
7272
>useConstraintInName : boolean
@@ -79,8 +79,8 @@ module TypeScript {
7979
> : ^^^
8080
}
8181
public getScopedNameEx<A,B,C>(scopeSymbol?: PullSymbol, useConstraintInName?: boolean, getPrettyTypeName?: boolean, getTypeParamMarkerInfo?: boolean) {
82-
>getScopedNameEx : <A, B, C>(scopeSymbol?: any, useConstraintInName?: boolean, getPrettyTypeName?: boolean, getTypeParamMarkerInfo?: boolean) => any
83-
> : ^^^^^^^^^^ ^^^^^^^^ ^^^ ^^ ^^^ ^^ ^^^ ^^^^^^^^
82+
>getScopedNameEx : <A, B, C>(scopeSymbol?: PullSymbol, useConstraintInName?: boolean, getPrettyTypeName?: boolean, getTypeParamMarkerInfo?: boolean) => any
83+
> : ^^^^^^^^^^ ^^^ ^^ ^^^ ^^ ^^^ ^^ ^^^ ^^^^^^^^
8484
>scopeSymbol : any
8585
> : ^^^
8686
>useConstraintInName : boolean

tests/baselines/reference/genericTypeReferenceWithoutTypeArgument.d.types

+6-6
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ declare var c: C;
1818
> : ^^^
1919

2020
declare var a: { x: C };
21-
>a : { x: any; }
22-
> : ^^^^^^^^^^^
21+
>a : { x: C; }
22+
> : ^^^^^ ^^^
2323
>x : any
2424
> : ^^^
2525

2626
declare var b: { (x: C): C };
27-
>b : (x: any) => any
28-
> : ^ ^^^^^^^^^^^^^
27+
>b : (x: C) => any
28+
> : ^ ^^ ^^^^^^^^
2929
>x : any
3030
> : ^^^
3131

@@ -36,8 +36,8 @@ declare var d: { [x: C]: C };
3636
> : ^^^
3737

3838
declare function f(x: C): C;
39-
>f : (x: any) => any
40-
> : ^ ^^^^^^^^^^^^^
39+
>f : (x: C) => any
40+
> : ^ ^^ ^^^^^^^^
4141
>x : any
4242
> : ^^^
4343

0 commit comments

Comments
 (0)