Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Enable for namespace exports
  • Loading branch information
andrewbranch committed Jan 12, 2023
commit 23e4a1448a3ff6f9f2a47db377f94bf0f91a8ffb
4 changes: 2 additions & 2 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3386,7 +3386,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
if (result && errorLocation && meaning & SymbolFlags.Value && result.flags & SymbolFlags.Alias && !(result.flags & SymbolFlags.Value) && !isValidTypeOnlyAliasUseSite(errorLocation)) {
const typeOnlyDeclaration = getTypeOnlyAliasDeclaration(result, SymbolFlags.Value);
if (typeOnlyDeclaration) {
const message = typeOnlyDeclaration.kind === SyntaxKind.ExportSpecifier || typeOnlyDeclaration.kind === SyntaxKind.ExportDeclaration
const message = typeOnlyDeclaration.kind === SyntaxKind.ExportSpecifier || typeOnlyDeclaration.kind === SyntaxKind.ExportDeclaration || typeOnlyDeclaration.kind === SyntaxKind.NamespaceExport
? Diagnostics._0_cannot_be_used_as_a_value_because_it_was_exported_using_export_type
: Diagnostics._0_cannot_be_used_as_a_value_because_it_was_imported_using_import_type;
const unescapedName = unescapeLeadingUnderscores(name);
Expand All @@ -3407,7 +3407,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
diagnostic,
createDiagnosticForNode(
typeOnlyDeclaration,
typeOnlyDeclaration.kind === SyntaxKind.ExportSpecifier || typeOnlyDeclaration.kind === SyntaxKind.ExportDeclaration
typeOnlyDeclaration.kind === SyntaxKind.ExportSpecifier || typeOnlyDeclaration.kind === SyntaxKind.ExportDeclaration || typeOnlyDeclaration.kind === SyntaxKind.NamespaceExport
? Diagnostics._0_was_exported_here
: Diagnostics._0_was_imported_here,
unescapedName));
Expand Down
2 changes: 2 additions & 0 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3818,6 +3818,7 @@ export type TypeOnlyCompatibleAliasDeclaration =
| NamespaceImport
| ImportOrExportSpecifier
| ExportDeclaration
| NamespaceExport
;

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

/**
Expand Down
3 changes: 3 additions & 0 deletions src/compiler/utilitiesPublic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ import {
NamedExportBindings,
NamedImportBindings,
NamespaceBody,
NamespaceExport,
NamespaceImport,
NewExpression,
Node,
Expand Down Expand Up @@ -1461,6 +1462,8 @@ export function isTypeOnlyImportOrExportDeclaration(node: Node): node is TypeOnl
return (node as ImportClause | ImportEqualsDeclaration).isTypeOnly;
case SyntaxKind.ExportDeclaration:
return (node as ExportDeclaration).isTypeOnly && !!(node as ExportDeclaration).moduleSpecifier && !(node as ExportDeclaration).exportClause;
case SyntaxKind.NamespaceExport:
return (node as NamespaceExport).parent.isTypeOnly;
default:
return false;
}
Expand Down
15 changes: 15 additions & 0 deletions tests/baselines/reference/exportNamespace10.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/c.ts(2,19): error TS1362: 'ns' cannot be used as a value because it was exported using 'export type'.


==== /a.ts (0 errors) ====
export class A {}

==== /b.ts (0 errors) ====
export type * as ns from "./a";

==== /c.ts (1 errors) ====
import { ns } from "./b";
let _: ns.A = new ns.A(); // Error
~~
!!! error TS1362: 'ns' cannot be used as a value because it was exported using 'export type'.
!!! related TS1377 /b.ts:1:13: 'ns' was exported here.
29 changes: 29 additions & 0 deletions tests/baselines/reference/exportNamespace10.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//// [tests/cases/conformance/externalModules/typeOnly/exportNamespace10.ts] ////

//// [a.ts]
export class A {}

//// [b.ts]
export type * as ns from "./a";

//// [c.ts]
import { ns } from "./b";
let _: ns.A = new ns.A(); // Error

//// [a.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.A = void 0;
var A = /** @class */ (function () {
function A() {
}
return A;
}());
exports.A = A;
//// [b.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//// [c.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var _ = new ns.A(); // Error
20 changes: 20 additions & 0 deletions tests/baselines/reference/exportNamespace10.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
=== /a.ts ===
export class A {}
>A : Symbol(A, Decl(a.ts, 0, 0))

=== /b.ts ===
export type * as ns from "./a";
>ns : Symbol(ns, Decl(b.ts, 0, 11))

=== /c.ts ===
import { ns } from "./b";
>ns : Symbol(ns, Decl(c.ts, 0, 8))

let _: ns.A = new ns.A(); // Error
>_ : Symbol(_, Decl(c.ts, 1, 3))
>ns : Symbol(ns, Decl(c.ts, 0, 8))
>A : Symbol(ns.A, Decl(a.ts, 0, 0))
>ns.A : Symbol(ns.A, Decl(a.ts, 0, 0))
>ns : Symbol(ns, Decl(c.ts, 0, 8))
>A : Symbol(ns.A, Decl(a.ts, 0, 0))

20 changes: 20 additions & 0 deletions tests/baselines/reference/exportNamespace10.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
=== /a.ts ===
export class A {}
>A : A

=== /b.ts ===
export type * as ns from "./a";
>ns : typeof import("/a")

=== /c.ts ===
import { ns } from "./b";
>ns : typeof ns

let _: ns.A = new ns.A(); // Error
>_ : ns.A
>ns : any
>new ns.A() : ns.A
>ns.A : typeof ns.A
>ns : typeof ns
>A : typeof ns.A

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// @Filename: /a.ts
export class A {}

// @Filename: /b.ts
export type * as ns from "./a";

// @Filename: /c.ts
import { ns } from "./b";
let _: ns.A = new ns.A(); // Error