Skip to content

Commit

Permalink
Fix false error on unresolved import
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewbranch committed Nov 17, 2023
1 parent 7064af4 commit 7b2dee6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45864,6 +45864,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
if (!isIllegalExportDefaultInCJS && getIsolatedModules(compilerOptions) && !(sym.flags & SymbolFlags.Value)) {
if (
sym.flags & SymbolFlags.Alias
&& resolveAlias(sym) !== unknownSymbol
&& getSymbolFlags(sym, /*excludeTypeOnlyMeanings*/ false, /*excludeLocalMeanings*/ true) & SymbolFlags.Type
&& (!typeOnlyDeclaration || getSourceFileOfNode(typeOnlyDeclaration) !== getSourceFileOfNode(node))
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,9 @@
export default T; // Error
~
!!! error TS1292: 'T' resolves to a type and must be marked type-only in this file before re-exporting when 'isolatedModules' is enabled. Consider using 'export type { T as default }'.

==== /test4.ts (0 errors) ====
// @ts-expect-error
import unresolved from "./doesntexist";
export default unresolved;

11 changes: 11 additions & 0 deletions tests/baselines/reference/isolatedModulesExportDeclarationType.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ export default T; // Transpiler could assume the alias resolves to a value?
import { T } from "./type";
export default T; // Error

//// [test4.ts]
// @ts-expect-error
import unresolved from "./doesntexist";
export default unresolved;


//// [type.js]
"use strict";
Expand All @@ -32,3 +37,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
//// [test3.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//// [test4.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// @ts-expect-error
var doesntexist_1 = require("./doesntexist");
exports.default = doesntexist_1.default;
5 changes: 5 additions & 0 deletions tests/cases/compiler/isolatedModulesExportDeclarationType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ export default T; // Transpiler could assume the alias resolves to a value?
// @Filename: /test3.ts
import { T } from "./type";
export default T; // Error

// @Filename: /test4.ts
// @ts-expect-error
import unresolved from "./doesntexist";
export default unresolved;

0 comments on commit 7b2dee6

Please sign in to comment.