Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Account for JS file type-only exports
  • Loading branch information
JoshuaKGoldberg committed Apr 18, 2023
commit 5644a4f603e8f6f66d739abf2c488e50c4fea284
6 changes: 5 additions & 1 deletion src/services/completions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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));
Comment thread
sandersn marked this conversation as resolved.
Outdated
}
}

function getLabelCompletionAtPosition(node: BreakOrContinueStatement): CompletionInfo | undefined {
Expand Down
14 changes: 14 additions & 0 deletions tests/cases/fourslash/javascriptModulesTypeImportAsValue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/// <reference path='fourslash.ts'/>
// @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" });