diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 2830de0c49d98..a97f3596e9a03 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -39940,6 +39940,9 @@ namespace ts { name ); } + if (isType && node.kind === SyntaxKind.ImportEqualsDeclaration && hasEffectiveModifier(node, ModifierFlags.Export)) { + error(node, Diagnostics.Cannot_use_export_import_on_a_type_or_type_only_namespace_when_the_isolatedModules_flag_is_provided); + } break; } case SyntaxKind.ExportSpecifier: { diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index cd4f562612a9a..f8a2cfafe6e66 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -867,6 +867,10 @@ "category": "Error", "code": 1268 }, + "Cannot use 'export import' on a type or type-only namespace when the '--isolatedModules' flag is provided.": { + "category": "Error", + "code": 1269 + }, "'with' statements are not allowed in an async function block.": { "category": "Error", @@ -1421,7 +1425,7 @@ "category": "Error", "code": 1474 }, - + "The types of '{0}' are incompatible between these types.": { "category": "Error", "code": 2200 diff --git a/tests/baselines/reference/isolatedModulesExportImportUninstantiatedNamespace.errors.txt b/tests/baselines/reference/isolatedModulesExportImportUninstantiatedNamespace.errors.txt new file mode 100644 index 0000000000000..f4d14877543d6 --- /dev/null +++ b/tests/baselines/reference/isolatedModulesExportImportUninstantiatedNamespace.errors.txt @@ -0,0 +1,25 @@ +tests/cases/compiler/factory.ts(3,1): error TS1269: Cannot use 'export import' on a type or type-only namespace when the '--isolatedModules' flag is provided. + + +==== tests/cases/compiler/jsx.ts (0 errors) ==== + export namespace JSXInternal { + export type HTMLAttributes = string + export type ComponentChildren = string + } + +==== tests/cases/compiler/factory.ts (1 errors) ==== + import { JSXInternal } from "./jsx" + + export import JSX = JSXInternal; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1269: Cannot use 'export import' on a type or type-only namespace when the '--isolatedModules' flag is provided. + + export function createElement( + tagName: string, + attributes: JSX.HTMLAttributes, + ...children: JSX.ComponentChildren[] + ): any { + //... + } + + \ No newline at end of file diff --git a/tests/baselines/reference/isolatedModulesExportImportUninstantiatedNamespace.js b/tests/baselines/reference/isolatedModulesExportImportUninstantiatedNamespace.js new file mode 100644 index 0000000000000..c2107c1b34f17 --- /dev/null +++ b/tests/baselines/reference/isolatedModulesExportImportUninstantiatedNamespace.js @@ -0,0 +1,33 @@ +//// [tests/cases/compiler/isolatedModulesExportImportUninstantiatedNamespace.ts] //// + +//// [jsx.ts] +export namespace JSXInternal { + export type HTMLAttributes = string + export type ComponentChildren = string +} + +//// [factory.ts] +import { JSXInternal } from "./jsx" + +export import JSX = JSXInternal; + +export function createElement( + tagName: string, + attributes: JSX.HTMLAttributes, + ...children: JSX.ComponentChildren[] +): any { + //... +} + + + +//// [jsx.js] +export {}; +//// [factory.js] +export function createElement(tagName, attributes) { + var children = []; + for (var _i = 2; _i < arguments.length; _i++) { + children[_i - 2] = arguments[_i]; + } + //... +} diff --git a/tests/baselines/reference/isolatedModulesReExportType.errors.txt b/tests/baselines/reference/isolatedModulesReExportType.errors.txt index 3d89ddf487a53..f615abd52c7ce 100644 --- a/tests/baselines/reference/isolatedModulesReExportType.errors.txt +++ b/tests/baselines/reference/isolatedModulesReExportType.errors.txt @@ -1,14 +1,17 @@ /user.ts(2,10): error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'. +/user.ts(3,1): error TS1269: Cannot use 'export import' on a type or type-only namespace when the '--isolatedModules' flag is provided. /user.ts(17,10): error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'. /user.ts(25,10): error TS1448: 'CC' resolves to a type-only declaration and must be re-exported using a type-only re-export when 'isolatedModules' is enabled. -==== /user.ts (3 errors) ==== +==== /user.ts (4 errors) ==== // Error, can't re-export something that's only a type. export { T } from "./exportT"; ~ !!! error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'. export import T2 = require("./exportEqualsT"); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1269: Cannot use 'export import' on a type or type-only namespace when the '--isolatedModules' flag is provided. // OK, has a value side export { C } from "./exportValue"; diff --git a/tests/cases/compiler/isolatedModulesExportImportUninstantiatedNamespace.ts b/tests/cases/compiler/isolatedModulesExportImportUninstantiatedNamespace.ts new file mode 100644 index 0000000000000..68582dc2ebd19 --- /dev/null +++ b/tests/cases/compiler/isolatedModulesExportImportUninstantiatedNamespace.ts @@ -0,0 +1,23 @@ +// @module: esnext +// @isolatedModules: true +// @noTypesAndSymbols: true + +// @Filename: jsx.ts +export namespace JSXInternal { + export type HTMLAttributes = string + export type ComponentChildren = string +} + +// @Filename: factory.ts +import { JSXInternal } from "./jsx" + +export import JSX = JSXInternal; + +export function createElement( + tagName: string, + attributes: JSX.HTMLAttributes, + ...children: JSX.ComponentChildren[] +): any { + //... +} +