Skip to content

Commit 5348903

Browse files
TypeScript Botandrewbranch
TypeScript Bot
andauthored
🤖 Pick PR microsoft#53385 (Add missing ambient check to `verba...) into release-5.0 (microsoft#53389)
Co-authored-by: Andrew Branch <[email protected]>
1 parent 3ec598c commit 5348903

File tree

5 files changed

+64
-6
lines changed

5 files changed

+64
-6
lines changed

‎src/compiler/checker.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -44164,15 +44164,15 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4416444164
if (getAllSymbolFlags(sym) & SymbolFlags.Value) {
4416544165
// However if it is a value, we need to check it's being used correctly
4416644166
checkExpressionCached(id);
44167-
if (!isIllegalExportDefaultInCJS && compilerOptions.verbatimModuleSyntax && getTypeOnlyAliasDeclaration(sym, SymbolFlags.Value)) {
44167+
if (!isIllegalExportDefaultInCJS && !(node.flags & NodeFlags.Ambient) && compilerOptions.verbatimModuleSyntax && getTypeOnlyAliasDeclaration(sym, SymbolFlags.Value)) {
4416844168
error(id,
4416944169
node.isExportEquals
4417044170
? Diagnostics.An_export_declaration_must_reference_a_real_value_when_verbatimModuleSyntax_is_enabled_but_0_resolves_to_a_type_only_declaration
4417144171
: Diagnostics.An_export_default_must_reference_a_real_value_when_verbatimModuleSyntax_is_enabled_but_0_resolves_to_a_type_only_declaration,
4417244172
idText(id));
4417344173
}
4417444174
}
44175-
else if (!isIllegalExportDefaultInCJS && compilerOptions.verbatimModuleSyntax) {
44175+
else if (!isIllegalExportDefaultInCJS && !(node.flags & NodeFlags.Ambient) && compilerOptions.verbatimModuleSyntax) {
4417644176
error(id,
4417744177
node.isExportEquals
4417844178
? Diagnostics.An_export_declaration_must_reference_a_value_when_verbatimModuleSyntax_is_enabled_but_0_only_refers_to_a_type
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
=== tests/cases/conformance/externalModules/type1.d.ts ===
2+
declare namespace NS {
3+
>NS : Symbol(NS, Decl(type1.d.ts, 0, 0))
4+
5+
type A = object;
6+
>A : Symbol(A, Decl(type1.d.ts, 0, 22))
7+
}
8+
9+
export = NS;
10+
>NS : Symbol(NS, Decl(type1.d.ts, 0, 0))
11+
12+
export as namespace MyTypes;
13+
>MyTypes : Symbol(MyTypes, Decl(type1.d.ts, 4, 12))
14+
15+
=== tests/cases/conformance/externalModules/type2.d.ts ===
16+
import type * as NS from './type1';
17+
>NS : Symbol(NS, Decl(type2.d.ts, 0, 11))
18+
19+
export = NS;
20+
>NS : Symbol(NS, Decl(type2.d.ts, 0, 11))
21+
22+
export as namespace ModuleATypes;
23+
>ModuleATypes : Symbol(ModuleATypes, Decl(type2.d.ts, 2, 12))
24+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
=== tests/cases/conformance/externalModules/type1.d.ts ===
2+
declare namespace NS {
3+
type A = object;
4+
>A : object
5+
}
6+
7+
export = NS;
8+
>NS : any
9+
10+
export as namespace MyTypes;
11+
>MyTypes : error
12+
13+
=== tests/cases/conformance/externalModules/type2.d.ts ===
14+
import type * as NS from './type1';
15+
>NS : error
16+
17+
export = NS;
18+
>NS : any
19+
20+
export as namespace ModuleATypes;
21+
>ModuleATypes : error
22+

‎tests/baselines/reference/verbatimModuleSyntaxNoElisionCJS.errors.txt

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/a.ts(2,10): error TS1282: An 'export =' declaration must reference a value when 'verbatimModuleSyntax' is enabled, but 'I' only refers to a type.
22
/b.ts(1,1): error TS1484: 'I' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled.
33
/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.
4-
/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.
54

65

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

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

3835
==== /f.ts (0 errors) ====
3936
import type I = require("./e");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// @verbatimModuleSyntax: true
2+
3+
// @Filename: type1.d.ts
4+
declare namespace NS {
5+
type A = object;
6+
}
7+
8+
export = NS;
9+
export as namespace MyTypes;
10+
11+
// @Filename: type2.d.ts
12+
import type * as NS from './type1';
13+
14+
export = NS;
15+
export as namespace ModuleATypes;

0 commit comments

Comments
 (0)