--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
This commit is contained in:
Andy 2017-06-09 09:39:55 -07:00 committed by GitHub
parent cae1286b72
commit a2d524252c
4 changed files with 35 additions and 2 deletions

View File

@ -21789,7 +21789,10 @@ namespace ts {
}
// Don't allow to re-export something with no value side when `--isolatedModules` is set.
if (node.kind === SyntaxKind.ExportSpecifier && compilerOptions.isolatedModules && !(target.flags & SymbolFlags.Value)) {
if (compilerOptions.isolatedModules
&& node.kind === SyntaxKind.ExportSpecifier
&& !(target.flags & SymbolFlags.Value)
&& !isInAmbientContext(node)) {
error(node, Diagnostics.Cannot_re_export_a_type_when_the_isolatedModules_flag_is_provided);
}
}

View File

@ -35,4 +35,14 @@
declare type T = number;
export = T;
==== /node_modules/foo/bar.d.ts (0 errors) ====
export type T = number;
==== /node_modules/foo/index.d.ts (0 errors) ====
export { T } from "./bar"; // In a declaration file, so not an error.
==== /node_modules/baz/index.d.ts (0 errors) ====
declare module "baz" {
export { T } from "foo"; // Also allowed.
}

View File

@ -9,7 +9,17 @@ export class C {}
//// [exportEqualsT.ts]
declare type T = number;
export = T;
//// [bar.d.ts]
export type T = number;
//// [index.d.ts]
export { T } from "./bar"; // In a declaration file, so not an error.
//// [index.d.ts]
declare module "baz" {
export { T } from "foo"; // Also allowed.
}
//// [user.ts]
// Error, can't re-export something that's only a type.

View File

@ -10,6 +10,16 @@ export class C {}
declare type T = number;
export = T;
// @Filename: /node_modules/foo/bar.d.ts
export type T = number;
// @Filename: /node_modules/foo/index.d.ts
export { T } from "./bar"; // In a declaration file, so not an error.
// @Filename: /node_modules/baz/index.d.ts
declare module "baz" {
export { T } from "foo"; // Also allowed.
}
// @Filename: /user.ts
// Error, can't re-export something that's only a type.