Skip to content

Commit 23e4a14

Browse files
committed
Enable for namespace exports
1 parent ddae38d commit 23e4a14

File tree

8 files changed

+100
-2
lines changed

8 files changed

+100
-2
lines changed

src/compiler/checker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3386,7 +3386,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
33863386
if (result && errorLocation && meaning & SymbolFlags.Value && result.flags & SymbolFlags.Alias && !(result.flags & SymbolFlags.Value) && !isValidTypeOnlyAliasUseSite(errorLocation)) {
33873387
const typeOnlyDeclaration = getTypeOnlyAliasDeclaration(result, SymbolFlags.Value);
33883388
if (typeOnlyDeclaration) {
3389-
const message = typeOnlyDeclaration.kind === SyntaxKind.ExportSpecifier || typeOnlyDeclaration.kind === SyntaxKind.ExportDeclaration
3389+
const message = typeOnlyDeclaration.kind === SyntaxKind.ExportSpecifier || typeOnlyDeclaration.kind === SyntaxKind.ExportDeclaration || typeOnlyDeclaration.kind === SyntaxKind.NamespaceExport
33903390
? Diagnostics._0_cannot_be_used_as_a_value_because_it_was_exported_using_export_type
33913391
: Diagnostics._0_cannot_be_used_as_a_value_because_it_was_imported_using_import_type;
33923392
const unescapedName = unescapeLeadingUnderscores(name);
@@ -3407,7 +3407,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
34073407
diagnostic,
34083408
createDiagnosticForNode(
34093409
typeOnlyDeclaration,
3410-
typeOnlyDeclaration.kind === SyntaxKind.ExportSpecifier || typeOnlyDeclaration.kind === SyntaxKind.ExportDeclaration
3410+
typeOnlyDeclaration.kind === SyntaxKind.ExportSpecifier || typeOnlyDeclaration.kind === SyntaxKind.ExportDeclaration || typeOnlyDeclaration.kind === SyntaxKind.NamespaceExport
34113411
? Diagnostics._0_was_exported_here
34123412
: Diagnostics._0_was_imported_here,
34133413
unescapedName));

src/compiler/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3818,6 +3818,7 @@ export type TypeOnlyCompatibleAliasDeclaration =
38183818
| NamespaceImport
38193819
| ImportOrExportSpecifier
38203820
| ExportDeclaration
3821+
| NamespaceExport
38213822
;
38223823

38233824
export type TypeOnlyAliasDeclaration =
@@ -3827,6 +3828,7 @@ export type TypeOnlyAliasDeclaration =
38273828
| ImportSpecifier & ({ readonly isTypeOnly: true } | { readonly parent: NamedImports & { readonly parent: ImportClause & { readonly isTypeOnly: true } } })
38283829
| ExportSpecifier & ({ readonly isTypeOnly: true } | { readonly parent: NamedExports & { readonly parent: ExportDeclaration & { readonly isTypeOnly: true } } })
38293830
| ExportDeclaration & { readonly isTypeOnly: true } // export * from "mod"
3831+
| NamespaceExport & { readonly parent: ExportDeclaration & { readonly isTypeOnly: true } } // export * as ns from "mod"
38303832
;
38313833

38323834
/**

src/compiler/utilitiesPublic.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ import {
209209
NamedExportBindings,
210210
NamedImportBindings,
211211
NamespaceBody,
212+
NamespaceExport,
212213
NamespaceImport,
213214
NewExpression,
214215
Node,
@@ -1461,6 +1462,8 @@ export function isTypeOnlyImportOrExportDeclaration(node: Node): node is TypeOnl
14611462
return (node as ImportClause | ImportEqualsDeclaration).isTypeOnly;
14621463
case SyntaxKind.ExportDeclaration:
14631464
return (node as ExportDeclaration).isTypeOnly && !!(node as ExportDeclaration).moduleSpecifier && !(node as ExportDeclaration).exportClause;
1465+
case SyntaxKind.NamespaceExport:
1466+
return (node as NamespaceExport).parent.isTypeOnly;
14641467
default:
14651468
return false;
14661469
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/c.ts(2,19): error TS1362: 'ns' cannot be used as a value because it was exported using 'export type'.
2+
3+
4+
==== /a.ts (0 errors) ====
5+
export class A {}
6+
7+
==== /b.ts (0 errors) ====
8+
export type * as ns from "./a";
9+
10+
==== /c.ts (1 errors) ====
11+
import { ns } from "./b";
12+
let _: ns.A = new ns.A(); // Error
13+
~~
14+
!!! error TS1362: 'ns' cannot be used as a value because it was exported using 'export type'.
15+
!!! related TS1377 /b.ts:1:13: 'ns' was exported here.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//// [tests/cases/conformance/externalModules/typeOnly/exportNamespace10.ts] ////
2+
3+
//// [a.ts]
4+
export class A {}
5+
6+
//// [b.ts]
7+
export type * as ns from "./a";
8+
9+
//// [c.ts]
10+
import { ns } from "./b";
11+
let _: ns.A = new ns.A(); // Error
12+
13+
//// [a.js]
14+
"use strict";
15+
Object.defineProperty(exports, "__esModule", { value: true });
16+
exports.A = void 0;
17+
var A = /** @class */ (function () {
18+
function A() {
19+
}
20+
return A;
21+
}());
22+
exports.A = A;
23+
//// [b.js]
24+
"use strict";
25+
Object.defineProperty(exports, "__esModule", { value: true });
26+
//// [c.js]
27+
"use strict";
28+
Object.defineProperty(exports, "__esModule", { value: true });
29+
var _ = new ns.A(); // Error
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
=== /a.ts ===
2+
export class A {}
3+
>A : Symbol(A, Decl(a.ts, 0, 0))
4+
5+
=== /b.ts ===
6+
export type * as ns from "./a";
7+
>ns : Symbol(ns, Decl(b.ts, 0, 11))
8+
9+
=== /c.ts ===
10+
import { ns } from "./b";
11+
>ns : Symbol(ns, Decl(c.ts, 0, 8))
12+
13+
let _: ns.A = new ns.A(); // Error
14+
>_ : Symbol(_, Decl(c.ts, 1, 3))
15+
>ns : Symbol(ns, Decl(c.ts, 0, 8))
16+
>A : Symbol(ns.A, Decl(a.ts, 0, 0))
17+
>ns.A : Symbol(ns.A, Decl(a.ts, 0, 0))
18+
>ns : Symbol(ns, Decl(c.ts, 0, 8))
19+
>A : Symbol(ns.A, Decl(a.ts, 0, 0))
20+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
=== /a.ts ===
2+
export class A {}
3+
>A : A
4+
5+
=== /b.ts ===
6+
export type * as ns from "./a";
7+
>ns : typeof import("/a")
8+
9+
=== /c.ts ===
10+
import { ns } from "./b";
11+
>ns : typeof ns
12+
13+
let _: ns.A = new ns.A(); // Error
14+
>_ : ns.A
15+
>ns : any
16+
>new ns.A() : ns.A
17+
>ns.A : typeof ns.A
18+
>ns : typeof ns
19+
>A : typeof ns.A
20+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// @Filename: /a.ts
2+
export class A {}
3+
4+
// @Filename: /b.ts
5+
export type * as ns from "./a";
6+
7+
// @Filename: /c.ts
8+
import { ns } from "./b";
9+
let _: ns.A = new ns.A(); // Error

0 commit comments

Comments
 (0)