Skip to content

Commit

Permalink
fix type import check for default-import/re-export in js files (#57778)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonlyu123 committed Mar 27, 2024
1 parent f3f70df commit b0d5ae6
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/services/completions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2706,7 +2706,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,
}
});

0 comments on commit b0d5ae6

Please sign in to comment.