diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index cd4eeed7522..bcf95543d31 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1898,13 +1898,17 @@ namespace ts { function tryGetMemberInModuleExportsAndProperties(memberName: __String, moduleSymbol: Symbol): Symbol | undefined { const symbol = tryGetMemberInModuleExports(memberName, moduleSymbol); - if (!symbol) { - const exportEquals = resolveExternalModuleSymbol(moduleSymbol); - if (exportEquals !== moduleSymbol) { - return getPropertyOfType(getTypeOfSymbol(exportEquals), memberName); - } + if (symbol) { + return symbol; } - return symbol; + + const exportEquals = resolveExternalModuleSymbol(moduleSymbol); + if (exportEquals === moduleSymbol) { + return undefined; + } + + const type = getTypeOfSymbol(exportEquals); + return type.flags & TypeFlags.Primitive ? undefined : getPropertyOfType(type, memberName); } function getExportsOfSymbol(symbol: Symbol): SymbolTable { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index c7803c35ee0..c6d1c1327be 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2766,7 +2766,10 @@ namespace ts { getAmbientModules(): Symbol[]; tryGetMemberInModuleExports(memberName: string, moduleSymbol: Symbol): Symbol | undefined; - /** Unlike `tryGetMemberInModuleExports`, this includes properties of an `export =` value. */ + /** + * Unlike `tryGetMemberInModuleExports`, this includes properties of an `export =` value. + * Does *not* return properties of primitive types. + */ /* @internal */ tryGetMemberInModuleExportsAndProperties(memberName: string, moduleSymbol: Symbol): Symbol | undefined; getApparentType(type: Type): Type; getSuggestionForNonexistentProperty(node: Identifier, containingType: Type): string | undefined; diff --git a/tests/cases/fourslash/importNameCodeFixNewImportExportEqualsPrimitive.ts b/tests/cases/fourslash/importNameCodeFixNewImportExportEqualsPrimitive.ts new file mode 100644 index 00000000000..0b9dbb489dd --- /dev/null +++ b/tests/cases/fourslash/importNameCodeFixNewImportExportEqualsPrimitive.ts @@ -0,0 +1,9 @@ +/// + +////[|valueOf/*0*/();|] + +// @Filename: foo.ts +////declare var x: number; +////export = x; + +verify.not.codeFixAvailable(); // See GH#20191 diff --git a/tests/cases/fourslash/importNameCodeFixNewImportFile5.ts b/tests/cases/fourslash/importNameCodeFixNewImportFile5.ts index 28cf48d8a5f..b92befd9881 100644 --- a/tests/cases/fourslash/importNameCodeFixNewImportFile5.ts +++ b/tests/cases/fourslash/importNameCodeFixNewImportFile5.ts @@ -9,8 +9,8 @@ //// declare var x: MyStatic; //// export = x; -verify.importFixAtPosition([ +-verify.importFixAtPosition([ `import { bar } from "./foo"; bar();` -]); \ No newline at end of file +]);