diff --git a/src/services/completions.ts b/src/services/completions.ts index c896db562c680..e343dee36b766 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -2405,7 +2405,7 @@ export function getCompletionEntriesFromSymbols( } // When in a value location in a JS file, ignore symbols that definitely seem to be type-only - if (!isTypeOnlyLocation && isInJSFile(sourceFile) && !(symbol.flags & SymbolFlags.Value) && !isInJSFile(symbol.declarations?.[0]?.getSourceFile())) { + if (!isTypeOnlyLocation && isInJSFile(sourceFile) && symbolAppearsToBeTypeOnly(symbol)) { continue; } @@ -2503,6 +2503,10 @@ export function getCompletionEntriesFromSymbols( // expressions are value space (which includes the value namespaces) return !!(allFlags & SymbolFlags.Value); } + + function symbolAppearsToBeTypeOnly(symbol: Symbol): boolean { + return !(symbol.flags & SymbolFlags.Value) && (!isInJSFile(symbol.declarations?.[0]?.getSourceFile()) || !!(symbol.flags & SymbolFlags.Type)); + } } function getLabelCompletionAtPosition(node: BreakOrContinueStatement): CompletionInfo | undefined { diff --git a/tests/cases/fourslash/javascriptModulesTypeImportAsValue.ts b/tests/cases/fourslash/javascriptModulesTypeImportAsValue.ts new file mode 100644 index 0000000000000..f35230dbc17e0 --- /dev/null +++ b/tests/cases/fourslash/javascriptModulesTypeImportAsValue.ts @@ -0,0 +1,14 @@ +/// +// @allowJs: true + +// @Filename: types.js +//// /** +//// * @typedef {Object} Pet +//// * @prop {string} name +//// */ +//// module.exports = { a: 1 }; + +// @Filename: app.js +//// import { /**/ } from "./types" + +verify.completions({ marker: "", excludes: "Pet" });