Skip to content

Add missing ambient check to verbatimModuleSyntax export = error #53385

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44313,15 +44313,15 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
if (getAllSymbolFlags(sym) & SymbolFlags.Value) {
// However if it is a value, we need to check it's being used correctly
checkExpressionCached(id);
if (!isIllegalExportDefaultInCJS && compilerOptions.verbatimModuleSyntax && getTypeOnlyAliasDeclaration(sym, SymbolFlags.Value)) {
if (!isIllegalExportDefaultInCJS && !(node.flags & NodeFlags.Ambient) && compilerOptions.verbatimModuleSyntax && getTypeOnlyAliasDeclaration(sym, SymbolFlags.Value)) {
error(id,
node.isExportEquals
? Diagnostics.An_export_declaration_must_reference_a_real_value_when_verbatimModuleSyntax_is_enabled_but_0_resolves_to_a_type_only_declaration
: Diagnostics.An_export_default_must_reference_a_real_value_when_verbatimModuleSyntax_is_enabled_but_0_resolves_to_a_type_only_declaration,
idText(id));
}
}
else if (!isIllegalExportDefaultInCJS && compilerOptions.verbatimModuleSyntax) {
else if (!isIllegalExportDefaultInCJS && !(node.flags & NodeFlags.Ambient) && compilerOptions.verbatimModuleSyntax) {
error(id,
node.isExportEquals
? Diagnostics.An_export_declaration_must_reference_a_value_when_verbatimModuleSyntax_is_enabled_but_0_only_refers_to_a_type
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
=== tests/cases/conformance/externalModules/type1.d.ts ===
declare namespace NS {
>NS : Symbol(NS, Decl(type1.d.ts, 0, 0))

type A = object;
>A : Symbol(A, Decl(type1.d.ts, 0, 22))
}

export = NS;
>NS : Symbol(NS, Decl(type1.d.ts, 0, 0))

export as namespace MyTypes;
>MyTypes : Symbol(MyTypes, Decl(type1.d.ts, 4, 12))

=== tests/cases/conformance/externalModules/type2.d.ts ===
import type * as NS from './type1';
>NS : Symbol(NS, Decl(type2.d.ts, 0, 11))

export = NS;
>NS : Symbol(NS, Decl(type2.d.ts, 0, 11))

export as namespace ModuleATypes;
>ModuleATypes : Symbol(ModuleATypes, Decl(type2.d.ts, 2, 12))

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
=== tests/cases/conformance/externalModules/type1.d.ts ===
declare namespace NS {
type A = object;
>A : object
}

export = NS;
>NS : any

export as namespace MyTypes;
>MyTypes : error

=== tests/cases/conformance/externalModules/type2.d.ts ===
import type * as NS from './type1';
>NS : error

export = NS;
>NS : any

export as namespace ModuleATypes;
>ModuleATypes : error

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/a.ts(2,10): error TS1282: An 'export =' declaration must reference a value when 'verbatimModuleSyntax' is enabled, but 'I' only refers to a type.
/b.ts(1,1): error TS1484: 'I' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled.
/d.ts(3,10): error TS1283: An 'export =' declaration must reference a real value when 'verbatimModuleSyntax' is enabled, but 'J' resolves to a type-only declaration.
/e.d.ts(2,10): error TS1282: An 'export =' declaration must reference a value when 'verbatimModuleSyntax' is enabled, but 'I' only refers to a type.


==== /a.ts (1 errors) ====
Expand Down Expand Up @@ -29,11 +28,9 @@
~
!!! error TS1283: An 'export =' declaration must reference a real value when 'verbatimModuleSyntax' is enabled, but 'J' resolves to a type-only declaration.

==== /e.d.ts (1 errors) ====
==== /e.d.ts (0 errors) ====
interface I {}
export = I;
~
!!! error TS1282: An 'export =' declaration must reference a value when 'verbatimModuleSyntax' is enabled, but 'I' only refers to a type.

==== /f.ts (0 errors) ====
import type I = require("./e");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// @verbatimModuleSyntax: true

// @Filename: type1.d.ts
declare namespace NS {
type A = object;
}

export = NS;
export as namespace MyTypes;

// @Filename: type2.d.ts
import type * as NS from './type1';

export = NS;
export as namespace ModuleATypes;