Fix isolatedModules check for export assignments (#57148)

This commit is contained in:
Andrew Branch
2024-01-24 12:03:18 -08:00
committed by GitHub
parent 5043c50388
commit 94f4379bca
3 changed files with 32 additions and 5 deletions

View File

@@ -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";

View File

@@ -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) ====
@@ -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.

View File

@@ -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)