Merge pull request #15538 from Microsoft/isolated-modules_re-export-type

Don't allow to re-export a type when '--isolatedModules' is set
This commit is contained in:
Andy 2017-05-10 17:58:49 -07:00 committed by GitHub
commit 2ba89fc534
5 changed files with 135 additions and 0 deletions

View File

@ -21445,6 +21445,11 @@ namespace ts {
Diagnostics.Import_declaration_conflicts_with_local_declaration_of_0;
error(node, message, symbolToString(symbol));
}
// 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)) {
error(node, Diagnostics.Cannot_re_export_a_type_when_the_isolatedModules_flag_is_provided);
}
}
}

View File

@ -635,6 +635,10 @@
"category": "Error",
"code": 1203
},
"Cannot re-export a type when the '--isolatedModules' flag is provided.": {
"category": "Error",
"code": 1205
},
"Decorators are not valid here.": {
"category": "Error",
"code": 1206

View File

@ -0,0 +1,38 @@
/user.ts(2,10): error TS1205: Cannot re-export a type when the '--isolatedModules' flag is provided.
/user.ts(17,10): error TS1205: Cannot re-export a type when the '--isolatedModules' flag is provided.
==== /user.ts (2 errors) ====
// Error, can't re-export something that's only a type.
export { T } from "./exportT";
~
!!! error TS1205: Cannot re-export a type when the '--isolatedModules' flag is provided.
export import T2 = require("./exportEqualsT");
// OK, has a value side
export { C } from "./exportValue";
// OK, even though the namespace it exports is only types.
import * as NS from "./exportT";
export { NS };
// OK, syntactically clear that a type is being re-exported.
export type T3 = T;
// Error, not clear (to an isolated module) whether `T4` is a type.
import { T } from "./exportT";
export { T as T4 };
~~~~~~~
!!! error TS1205: Cannot re-export a type when the '--isolatedModules' flag is provided.
==== /exportT.ts (0 errors) ====
export type T = number;
==== /exportValue.ts (0 errors) ====
export class C {}
==== /exportEqualsT.ts (0 errors) ====
declare type T = number;
export = T;

View File

@ -0,0 +1,57 @@
//// [tests/cases/compiler/isolatedModulesReExportType.ts] ////
//// [exportT.ts]
export type T = number;
//// [exportValue.ts]
export class C {}
//// [exportEqualsT.ts]
declare type T = number;
export = T;
//// [user.ts]
// Error, can't re-export something that's only a type.
export { T } from "./exportT";
export import T2 = require("./exportEqualsT");
// OK, has a value side
export { C } from "./exportValue";
// OK, even though the namespace it exports is only types.
import * as NS from "./exportT";
export { NS };
// OK, syntactically clear that a type is being re-exported.
export type T3 = T;
// Error, not clear (to an isolated module) whether `T4` is a type.
import { T } from "./exportT";
export { T as T4 };
//// [exportT.js]
"use strict";
exports.__esModule = true;
//// [exportEqualsT.js]
"use strict";
exports.__esModule = true;
//// [exportValue.js]
"use strict";
exports.__esModule = true;
var C = (function () {
function C() {
}
return C;
}());
exports.C = C;
//// [user.js]
"use strict";
exports.__esModule = true;
// OK, has a value side
var exportValue_1 = require("./exportValue");
exports.C = exportValue_1.C;
// OK, even though the namespace it exports is only types.
var NS = require("./exportT");
exports.NS = NS;

View File

@ -0,0 +1,31 @@
// @isolatedModules: true
// @Filename: /exportT.ts
export type T = number;
// @Filename: /exportValue.ts
export class C {}
// @Filename: /exportEqualsT.ts
declare type T = number;
export = T;
// @Filename: /user.ts
// Error, can't re-export something that's only a type.
export { T } from "./exportT";
export import T2 = require("./exportEqualsT");
// OK, has a value side
export { C } from "./exportValue";
// OK, even though the namespace it exports is only types.
import * as NS from "./exportT";
export { NS };
// OK, syntactically clear that a type is being re-exported.
export type T3 = T;
// Error, not clear (to an isolated module) whether `T4` is a type.
import { T } from "./exportT";
export { T as T4 };