diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index dd24f9be315ee..54d21cf16f2cb 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -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"; diff --git a/tests/baselines/reference/exportDeclaration(isolatedmodules=true).errors.txt b/tests/baselines/reference/exportDeclaration(isolatedmodules=true).errors.txt index 73ad311dfd554..bd131b47538a7 100644 --- a/tests/baselines/reference/exportDeclaration(isolatedmodules=true).errors.txt +++ b/tests/baselines/reference/exportDeclaration(isolatedmodules=true).errors.txt @@ -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. \ No newline at end of file +!!! 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. \ No newline at end of file diff --git a/tests/cases/compiler/isolatedModulesReExportAlias.ts b/tests/cases/compiler/isolatedModulesReExportAlias.ts new file mode 100644 index 0000000000000..e27c06bc55f6b --- /dev/null +++ b/tests/cases/compiler/isolatedModulesReExportAlias.ts @@ -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) \ No newline at end of file