Skip to content

🤖 Pick PR #57148 (Fix isolatedModules check for expor...) into release-5.4 #57161

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

Closed
wants to merge 1 commit into from
Closed
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
7 changes: 4 additions & 3 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46384,11 +46384,12 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
);
}

if (!isIllegalExportDefaultInCJS && getIsolatedModules(compilerOptions) && !(sym.flags & SymbolFlags.Value)) {
if (!isIllegalExportDefaultInCJS && !(node.flags & NodeFlags.Ambient) && getIsolatedModules(compilerOptions) && !(sym.flags & SymbolFlags.Value)) {
const nonLocalMeanings = getSymbolFlags(sym, /*excludeTypeOnlyMeanings*/ false, /*excludeLocalMeanings*/ true);
if (
sym.flags & SymbolFlags.Alias
&& resolveAlias(sym) !== unknownSymbol
&& getSymbolFlags(sym, /*excludeTypeOnlyMeanings*/ false, /*excludeLocalMeanings*/ true) & SymbolFlags.Type
&& nonLocalMeanings & SymbolFlags.Type
&& !(nonLocalMeanings & SymbolFlags.Value)
&& (!typeOnlyDeclaration || getSourceFileOfNode(typeOnlyDeclaration) !== getSourceFileOfNode(node))
) {
// import { SomeType } from "./someModule";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/b.ts(3,5): error TS1362: 'A' cannot be used as a value because it was exported using 'export type'.
/d.ts(2,10): error TS1291: 'A' resolves to a type and must be marked type-only in this file before re-exporting when 'isolatedModules' is enabled. Consider using 'import type' where 'A' is imported.
/d.ts(2,10): error TS1289: 'A' resolves to a type-only declaration and must be marked type-only in this file before re-exporting when 'isolatedModules' is enabled. Consider using 'import type' where 'A' is imported.


==== /a.ts (0 errors) ====
Expand All @@ -22,4 +22,5 @@
import { A } from './a';
export = A;
~
!!! error TS1291: 'A' resolves to a type and must be marked type-only in this file before re-exporting when 'isolatedModules' is enabled. Consider using 'import type' where 'A' is imported.
!!! error TS1289: 'A' resolves to a type-only declaration and must be marked type-only in this file before re-exporting when 'isolatedModules' is enabled. Consider using 'import type' where 'A' is imported.
!!! related TS1377 /a.ts:2:15: 'A' was exported here.
25 changes: 25 additions & 0 deletions tests/cases/compiler/isolatedModulesReExportAlias.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// @isolatedModules: true
// @noEmit: true
// @noTypesAndSymbols: true

// @Filename: /events.d.ts
declare module "events" {
interface EventEmitterOptions {
captureRejections?: boolean;
}
class EventEmitter {
constructor(options?: EventEmitterOptions);
}
export = EventEmitter;
}
declare module "node:events" {
import events = require("events");
export = events;
}

// @Filename: /moreEvents.ts
import events = require("events");
export = events;

// @Filename: /boo.ts
// Bad test runner (ignores stuff when last file contains the string r-e-q-u-i-r-e)