From b754fc393738ae05aad136324a0dc78787745644 Mon Sep 17 00:00:00 2001 From: TypeScript Bot Date: Mon, 8 Apr 2024 10:58:14 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20Pick=20PR=20#57778=20(fix=20type?= =?UTF-8?q?=20import=20check=20for=20default-i...)=20into=20release-5.4=20?= =?UTF-8?q?(#58116)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Lyu, Wei-Da <36730922+jasonlyu123@users.noreply.github.com> --- src/services/completions.ts | 3 +- tests/cases/fourslash/jsFileImportNoTypes2.ts | 59 +++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/jsFileImportNoTypes2.ts diff --git a/src/services/completions.ts b/src/services/completions.ts index f41a00c716c8b..a074492cad678 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -2674,7 +2674,8 @@ export function getCompletionEntriesFromSymbols( } function symbolAppearsToBeTypeOnly(symbol: Symbol): boolean { - return !(symbol.flags & SymbolFlags.Value) && (!isInJSFile(symbol.declarations?.[0]) || !!(symbol.flags & SymbolFlags.Type)); + const flags = getCombinedLocalAndExportSymbolFlags(skipAlias(symbol, typeChecker)); + return !(flags & SymbolFlags.Value) && (!isInJSFile(symbol.declarations?.[0]) || !!(flags & SymbolFlags.Type)); } } diff --git a/tests/cases/fourslash/jsFileImportNoTypes2.ts b/tests/cases/fourslash/jsFileImportNoTypes2.ts new file mode 100644 index 0000000000000..548cf0bd3332a --- /dev/null +++ b/tests/cases/fourslash/jsFileImportNoTypes2.ts @@ -0,0 +1,59 @@ +/// + +// @allowJs: true + +// @Filename: /default.ts +//// export default class TestDefaultClass {} + +// @Filename: /defaultType.ts +//// export default interface TestDefaultInterface {} + +// @Filename: /reExport/toReExport.ts +//// export class TestClassReExport {} +//// export interface TestInterfaceReExport {} + +// @Filename: /reExport/index.ts +//// export { TestClassReExport, TestInterfaceReExport } from './toReExport'; + +// @Filename: /exportList.ts +//// class TestClassExportList {}; +//// interface TestInterfaceExportList {}; +//// export { TestClassExportList, TestInterfaceExportList }; + +// @Filename: /baseline.ts +//// export class TestClassBaseline {} +//// export interface TestInterfaceBaseline {} + +// @Filename: /a.js +//// import /**/ + +verify.completions({ + marker: "", + isNewIdentifierLocation: true, + exact: [ + { + name: "TestClassBaseline", + insertText: "import { TestClassBaseline } from \"./baseline\";", + source: "./baseline", + }, + { + name: "TestClassExportList", + insertText: "import { TestClassExportList } from \"./exportList\";", + source: "./exportList", + }, + { + name: "TestClassReExport", + insertText: "import { TestClassReExport } from \"./reExport\";", + source: "./reExport", + }, + { + name: "TestDefaultClass", + insertText: "import TestDefaultClass from \"./default\";", + source: "./default", + }, + ], + preferences: { + includeCompletionsForImportStatements: true, + includeCompletionsWithInsertText: true, + } +});