Skip to content

Commit 94f4379

Browse files
authored
Fix isolatedModules check for export assignments (#57148)
1 parent 5043c50 commit 94f4379

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

src/compiler/checker.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46384,11 +46384,12 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4638446384
);
4638546385
}
4638646386

46387-
if (!isIllegalExportDefaultInCJS && getIsolatedModules(compilerOptions) && !(sym.flags & SymbolFlags.Value)) {
46387+
if (!isIllegalExportDefaultInCJS && !(node.flags & NodeFlags.Ambient) && getIsolatedModules(compilerOptions) && !(sym.flags & SymbolFlags.Value)) {
46388+
const nonLocalMeanings = getSymbolFlags(sym, /*excludeTypeOnlyMeanings*/ false, /*excludeLocalMeanings*/ true);
4638846389
if (
4638946390
sym.flags & SymbolFlags.Alias
46390-
&& resolveAlias(sym) !== unknownSymbol
46391-
&& getSymbolFlags(sym, /*excludeTypeOnlyMeanings*/ false, /*excludeLocalMeanings*/ true) & SymbolFlags.Type
46391+
&& nonLocalMeanings & SymbolFlags.Type
46392+
&& !(nonLocalMeanings & SymbolFlags.Value)
4639246393
&& (!typeOnlyDeclaration || getSourceFileOfNode(typeOnlyDeclaration) !== getSourceFileOfNode(node))
4639346394
) {
4639446395
// import { SomeType } from "./someModule";

tests/baselines/reference/exportDeclaration(isolatedmodules=true).errors.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/b.ts(3,5): error TS1362: 'A' cannot be used as a value because it was exported using 'export type'.
2-
/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.
2+
/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.
33

44

55
==== /a.ts (0 errors) ====
@@ -22,4 +22,5 @@
2222
import { A } from './a';
2323
export = A;
2424
~
25-
!!! 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.
25+
!!! 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.
26+
!!! related TS1377 /a.ts:2:15: 'A' was exported here.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// @isolatedModules: true
2+
// @noEmit: true
3+
// @noTypesAndSymbols: true
4+
5+
// @Filename: /events.d.ts
6+
declare module "events" {
7+
interface EventEmitterOptions {
8+
captureRejections?: boolean;
9+
}
10+
class EventEmitter {
11+
constructor(options?: EventEmitterOptions);
12+
}
13+
export = EventEmitter;
14+
}
15+
declare module "node:events" {
16+
import events = require("events");
17+
export = events;
18+
}
19+
20+
// @Filename: /moreEvents.ts
21+
import events = require("events");
22+
export = events;
23+
24+
// @Filename: /boo.ts
25+
// Bad test runner (ignores stuff when last file contains the string r-e-q-u-i-r-e)

0 commit comments

Comments
 (0)