Skip to content

Commit 0655f32

Browse files
authored
Add missing isolatedModules error for export import (#47838)
* Add missing isolatedModules error for `export import` * Update existing baseline
1 parent 954d044 commit 0655f32

6 files changed

+93
-2
lines changed

src/compiler/checker.ts

+3
Original file line numberDiff line numberDiff line change
@@ -39940,6 +39940,9 @@ namespace ts {
3994039940
name
3994139941
);
3994239942
}
39943+
if (isType && node.kind === SyntaxKind.ImportEqualsDeclaration && hasEffectiveModifier(node, ModifierFlags.Export)) {
39944+
error(node, Diagnostics.Cannot_use_export_import_on_a_type_or_type_only_namespace_when_the_isolatedModules_flag_is_provided);
39945+
}
3994339946
break;
3994439947
}
3994539948
case SyntaxKind.ExportSpecifier: {

src/compiler/diagnosticMessages.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,10 @@
867867
"category": "Error",
868868
"code": 1268
869869
},
870+
"Cannot use 'export import' on a type or type-only namespace when the '--isolatedModules' flag is provided.": {
871+
"category": "Error",
872+
"code": 1269
873+
},
870874

871875
"'with' statements are not allowed in an async function block.": {
872876
"category": "Error",
@@ -1421,7 +1425,7 @@
14211425
"category": "Error",
14221426
"code": 1474
14231427
},
1424-
1428+
14251429
"The types of '{0}' are incompatible between these types.": {
14261430
"category": "Error",
14271431
"code": 2200
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
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.
2+
3+
4+
==== tests/cases/compiler/jsx.ts (0 errors) ====
5+
export namespace JSXInternal {
6+
export type HTMLAttributes = string
7+
export type ComponentChildren = string
8+
}
9+
10+
==== tests/cases/compiler/factory.ts (1 errors) ====
11+
import { JSXInternal } from "./jsx"
12+
13+
export import JSX = JSXInternal;
14+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15+
!!! error TS1269: Cannot use 'export import' on a type or type-only namespace when the '--isolatedModules' flag is provided.
16+
17+
export function createElement<ElementType extends HTMLElement>(
18+
tagName: string,
19+
attributes: JSX.HTMLAttributes,
20+
...children: JSX.ComponentChildren[]
21+
): any {
22+
//...
23+
}
24+
25+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//// [tests/cases/compiler/isolatedModulesExportImportUninstantiatedNamespace.ts] ////
2+
3+
//// [jsx.ts]
4+
export namespace JSXInternal {
5+
export type HTMLAttributes = string
6+
export type ComponentChildren = string
7+
}
8+
9+
//// [factory.ts]
10+
import { JSXInternal } from "./jsx"
11+
12+
export import JSX = JSXInternal;
13+
14+
export function createElement<ElementType extends HTMLElement>(
15+
tagName: string,
16+
attributes: JSX.HTMLAttributes,
17+
...children: JSX.ComponentChildren[]
18+
): any {
19+
//...
20+
}
21+
22+
23+
24+
//// [jsx.js]
25+
export {};
26+
//// [factory.js]
27+
export function createElement(tagName, attributes) {
28+
var children = [];
29+
for (var _i = 2; _i < arguments.length; _i++) {
30+
children[_i - 2] = arguments[_i];
31+
}
32+
//...
33+
}

tests/baselines/reference/isolatedModulesReExportType.errors.txt

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
/user.ts(2,10): error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
2+
/user.ts(3,1): error TS1269: Cannot use 'export import' on a type or type-only namespace when the '--isolatedModules' flag is provided.
23
/user.ts(17,10): error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
34
/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.
45

56

6-
==== /user.ts (3 errors) ====
7+
==== /user.ts (4 errors) ====
78
// Error, can't re-export something that's only a type.
89
export { T } from "./exportT";
910
~
1011
!!! error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
1112
export import T2 = require("./exportEqualsT");
13+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
14+
!!! error TS1269: Cannot use 'export import' on a type or type-only namespace when the '--isolatedModules' flag is provided.
1215

1316
// OK, has a value side
1417
export { C } from "./exportValue";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// @module: esnext
2+
// @isolatedModules: true
3+
// @noTypesAndSymbols: true
4+
5+
// @Filename: jsx.ts
6+
export namespace JSXInternal {
7+
export type HTMLAttributes = string
8+
export type ComponentChildren = string
9+
}
10+
11+
// @Filename: factory.ts
12+
import { JSXInternal } from "./jsx"
13+
14+
export import JSX = JSXInternal;
15+
16+
export function createElement<ElementType extends HTMLElement>(
17+
tagName: string,
18+
attributes: JSX.HTMLAttributes,
19+
...children: JSX.ComponentChildren[]
20+
): any {
21+
//...
22+
}
23+

0 commit comments

Comments
 (0)