Fix bug: Still implement a method even if the return type is defined in another file (#24978)

This commit is contained in:
Andy
2018-06-19 16:36:18 -07:00
committed by GitHub
parent 9706f1729e
commit b3f9ec3796
4 changed files with 40 additions and 6 deletions

View File

@@ -4110,15 +4110,14 @@ namespace ts {
if (declaration.parent && declaration.parent.kind === SyntaxKind.VariableDeclaration) {
return declarationNameToString((<VariableDeclaration>declaration.parent).name);
}
if (context && !context.encounteredError && !(context.flags & NodeBuilderFlags.AllowAnonymousIdentifier)) {
context.encounteredError = true;
}
switch (declaration.kind) {
case SyntaxKind.ClassExpression:
return "(Anonymous class)";
case SyntaxKind.FunctionExpression:
case SyntaxKind.ArrowFunction:
return "(Anonymous function)";
if (context && !context.encounteredError && !(context.flags & NodeBuilderFlags.AllowAnonymousIdentifier)) {
context.encounteredError = true;
}
return declaration.kind === SyntaxKind.ClassExpression ? "(Anonymous class)" : "(Anonymous function)";
}
}
const nameType = symbol.nameType;

View File

@@ -3066,6 +3066,7 @@ namespace ts {
Subtype
}
// NOTE: If modifying this enum, must modify `TypeFormatFlags` too!
export const enum NodeBuilderFlags {
None = 0,
// Options

View File

@@ -0,0 +1,25 @@
/// <reference path='fourslash.ts' />
// @Filename: /I.ts
////export interface J {}
////export interface I {
//// x: J;
//// m(): J;
////}
// @Filename: /C.ts
////import { I } from "./I";
////export class C implements I {}
goTo.file("/C.ts");
verify.codeFix({
description: "Implement interface 'I'",
newFileContent:
`import { I } from "./I";
export class C implements I {
x: import("/I").J;
m(): import("/I").J {
throw new Error("Method not implemented.");
}
}`,
});

View File

@@ -13,4 +13,13 @@
////}
goTo.file("/b.ts");
verify.not.codeFixAvailable();
verify.codeFix({
index: 0,
description: "Infer type of 'x' from usage",
newFileContent:
`export class C {
set x(val: Promise<typeof import("/a")>) { val; }
method() { this.x = import("./a"); }
}`,
});