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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 6 additions & 6 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 12 additions & 12 deletions
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
}

0 commit comments

Comments
 (0)