mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-07 05:41:22 -06:00
--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:
parent
cae1286b72
commit
a2d524252c
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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.
|
||||
}
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user