Skip to content

Commit b3f9ec3

Browse files
author
Andy
authored
Fix bug: Still implement a method even if the return type is defined in another file (microsoft#24978)
1 parent 9706f17 commit b3f9ec3

4 files changed

Lines changed: 40 additions & 6 deletions

File tree

src/compiler/checker.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4110,15 +4110,14 @@ namespace ts {
41104110
if (declaration.parent && declaration.parent.kind === SyntaxKind.VariableDeclaration) {
41114111
return declarationNameToString((<VariableDeclaration>declaration.parent).name);
41124112
}
4113-
if (context && !context.encounteredError && !(context.flags & NodeBuilderFlags.AllowAnonymousIdentifier)) {
4114-
context.encounteredError = true;
4115-
}
41164113
switch (declaration.kind) {
41174114
case SyntaxKind.ClassExpression:
4118-
return "(Anonymous class)";
41194115
case SyntaxKind.FunctionExpression:
41204116
case SyntaxKind.ArrowFunction:
4121-
return "(Anonymous function)";
4117+
if (context && !context.encounteredError && !(context.flags & NodeBuilderFlags.AllowAnonymousIdentifier)) {
4118+
context.encounteredError = true;
4119+
}
4120+
return declaration.kind === SyntaxKind.ClassExpression ? "(Anonymous class)" : "(Anonymous function)";
41224121
}
41234122
}
41244123
const nameType = symbol.nameType;

src/compiler/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3066,6 +3066,7 @@ namespace ts {
30663066
Subtype
30673067
}
30683068

3069+
// NOTE: If modifying this enum, must modify `TypeFormatFlags` too!
30693070
export const enum NodeBuilderFlags {
30703071
None = 0,
30713072
// Options
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @Filename: /I.ts
4+
////export interface J {}
5+
////export interface I {
6+
//// x: J;
7+
//// m(): J;
8+
////}
9+
10+
// @Filename: /C.ts
11+
////import { I } from "./I";
12+
////export class C implements I {}
13+
14+
goTo.file("/C.ts");
15+
verify.codeFix({
16+
description: "Implement interface 'I'",
17+
newFileContent:
18+
`import { I } from "./I";
19+
export class C implements I {
20+
x: import("/I").J;
21+
m(): import("/I").J {
22+
throw new Error("Method not implemented.");
23+
}
24+
}`,
25+
});

tests/cases/fourslash/codeFixInferFromUsageSetterWithInaccessibleType.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,13 @@
1313
////}
1414

1515
goTo.file("/b.ts");
16-
verify.not.codeFixAvailable();
16+
verify.codeFix({
17+
index: 0,
18+
description: "Infer type of 'x' from usage",
19+
newFileContent:
20+
`export class C {
21+
set x(val: Promise<typeof import("/a")>) { val; }
22+
method() { this.x = import("./a"); }
23+
}`,
24+
});
25+

0 commit comments

Comments
 (0)