Skip to content

fix type import check for default-import/re-export in js files #57778

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion src/services/completions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2704,7 +2704,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));
}
}

Expand Down
59 changes: 59 additions & 0 deletions tests/cases/fourslash/jsFileImportNoTypes2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/// <reference path="fourslash.ts" />

// @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,
}
});