Skip to content

Commit a2d5242

Browse files
author
Andy
authored
--isolatedModules: Still allow re-export of type in a declaration file (#16399)
* --isolatedModules: Still allow re-export of type in a declaration file * Use isInAmbientContext
1 parent cae1286 commit a2d5242

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

src/compiler/checker.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21789,7 +21789,10 @@ namespace ts {
2178921789
}
2179021790

2179121791
// Don't allow to re-export something with no value side when `--isolatedModules` is set.
21792-
if (node.kind === SyntaxKind.ExportSpecifier && compilerOptions.isolatedModules && !(target.flags & SymbolFlags.Value)) {
21792+
if (compilerOptions.isolatedModules
21793+
&& node.kind === SyntaxKind.ExportSpecifier
21794+
&& !(target.flags & SymbolFlags.Value)
21795+
&& !isInAmbientContext(node)) {
2179321796
error(node, Diagnostics.Cannot_re_export_a_type_when_the_isolatedModules_flag_is_provided);
2179421797
}
2179521798
}

tests/baselines/reference/isolatedModulesReExportType.errors.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,14 @@
3535
declare type T = number;
3636
export = T;
3737

38+
==== /node_modules/foo/bar.d.ts (0 errors) ====
39+
export type T = number;
40+
41+
==== /node_modules/foo/index.d.ts (0 errors) ====
42+
export { T } from "./bar"; // In a declaration file, so not an error.
43+
44+
==== /node_modules/baz/index.d.ts (0 errors) ====
45+
declare module "baz" {
46+
export { T } from "foo"; // Also allowed.
47+
}
3848

tests/baselines/reference/isolatedModulesReExportType.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,17 @@ export class C {}
99
//// [exportEqualsT.ts]
1010
declare type T = number;
1111
export = T;
12-
12+
13+
//// [bar.d.ts]
14+
export type T = number;
15+
16+
//// [index.d.ts]
17+
export { T } from "./bar"; // In a declaration file, so not an error.
18+
19+
//// [index.d.ts]
20+
declare module "baz" {
21+
export { T } from "foo"; // Also allowed.
22+
}
1323

1424
//// [user.ts]
1525
// Error, can't re-export something that's only a type.

tests/cases/compiler/isolatedModulesReExportType.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ export class C {}
1010
declare type T = number;
1111
export = T;
1212

13+
// @Filename: /node_modules/foo/bar.d.ts
14+
export type T = number;
15+
16+
// @Filename: /node_modules/foo/index.d.ts
17+
export { T } from "./bar"; // In a declaration file, so not an error.
18+
19+
// @Filename: /node_modules/baz/index.d.ts
20+
declare module "baz" {
21+
export { T } from "foo"; // Also allowed.
22+
}
1323

1424
// @Filename: /user.ts
1525
// Error, can't re-export something that's only a type.

0 commit comments

Comments
 (0)