Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a2d5242

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

4 files changed

+35-2Lines changed: 35 additions & 2 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/compiler/checker.ts‎

Copy file name to clipboardExpand all lines: src/compiler/checker.ts
+4-1Lines 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
}
Collapse file

‎tests/baselines/reference/isolatedModulesReExportType.errors.txt‎

Copy file name to clipboardExpand all lines: tests/baselines/reference/isolatedModulesReExportType.errors.txt
+10Lines 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

Collapse file

‎tests/baselines/reference/isolatedModulesReExportType.js‎

Copy file name to clipboardExpand all lines: tests/baselines/reference/isolatedModulesReExportType.js
+11-1Lines 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.
Collapse file

‎tests/cases/compiler/isolatedModulesReExportType.ts‎

Copy file name to clipboardExpand all lines: tests/cases/compiler/isolatedModulesReExportType.ts
+10Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.