diff --git a/src/services/codefixes/importFixes.ts b/src/services/codefixes/importFixes.ts index db2327654a394..e07beef3339f0 100644 --- a/src/services/codefixes/importFixes.ts +++ b/src/services/codefixes/importFixes.ts @@ -211,7 +211,7 @@ namespace ts.codefix { } function getImportFixForSymbol(sourceFile: SourceFile, exportInfos: readonly SymbolExportInfo[], moduleSymbol: Symbol, symbolName: string, program: Program, position: number | undefined, preferTypeOnlyImport: boolean, useRequire: boolean, host: LanguageServiceHost, preferences: UserPreferences) { - Debug.assert(exportInfos.some(info => info.moduleSymbol === moduleSymbol), "Some exportInfo should match the specified moduleSymbol"); + Debug.assert(exportInfos.some(info => info.moduleSymbol === moduleSymbol || info.symbol.parent === moduleSymbol), "Some exportInfo should match the specified moduleSymbol"); return getBestFix(getImportFixes(exportInfos, symbolName, position, preferTypeOnlyImport, useRequire, program, sourceFile, host, preferences), sourceFile, program, host, preferences); } diff --git a/tests/cases/fourslash/codeFixClassImplementInterfaceAutoImportsReExports.ts b/tests/cases/fourslash/codeFixClassImplementInterfaceAutoImportsReExports.ts new file mode 100644 index 0000000000000..c35a38baceb96 --- /dev/null +++ b/tests/cases/fourslash/codeFixClassImplementInterfaceAutoImportsReExports.ts @@ -0,0 +1,30 @@ +/// + +// @Filename: node_modules/test-module/index.d.ts +////declare namespace e { +//// interface Foo {} +////} +////export = e; + +// @Filename: a.ts +////import { Foo } from "test-module"; +////export interface A { +//// foo(): Foo; +////} + +// @Filename: b.ts +////import { A } from "./a"; +////export class B implements A {} + +goTo.file("b.ts"); +verify.codeFix({ + description: "Implement interface 'A'", + newFileContent: +`import { Foo } from "test-module"; +import { A } from "./a"; +export class B implements A { + foo(): Foo { + throw new Error("Method not implemented."); + } +}` +});