Skip to content

Commit b8a8cea

Browse files
Andysandersn
authored andcommitted
Handle merging unknownSymbol (#28453)
* Handle merging unknownSymbol * mergeSymbol of unknown target returns source, not unknown
1 parent dc03115 commit b8a8cea

File tree

5 files changed

+43
-1
lines changed

5 files changed

+43
-1
lines changed

src/compiler/checker.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,11 @@ namespace ts {
870870
(source.flags | target.flags) & SymbolFlags.Assignment) {
871871
Debug.assert(source !== target);
872872
if (!(target.flags & SymbolFlags.Transient)) {
873-
target = cloneSymbol(resolveSymbol(target));
873+
const resolvedTarget = resolveSymbol(target);
874+
if (resolvedTarget === unknownSymbol) {
875+
return source;
876+
}
877+
target = cloneSymbol(resolvedTarget);
874878
}
875879
// Javascript static-property-assignment declarations always merge, even though they are also values
876880
if (source.flags & SymbolFlags.ValueModule && target.flags & SymbolFlags.ValueModule && target.constEnumOnlyModule && !source.constEnumOnlyModule) {
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/a.d.ts(2,10): error TS2708: Cannot use namespace 'N' as a value.
2+
/a.d.ts(3,1): error TS2303: Circular definition of import alias 'N'.
3+
4+
5+
==== /a.d.ts (2 errors) ====
6+
declare global { namespace N {} }
7+
export = N;
8+
~
9+
!!! error TS2708: Cannot use namespace 'N' as a value.
10+
export as namespace N;
11+
~~~~~~~~~~~~~~~~~~~~~~
12+
!!! error TS2303: Circular definition of import alias 'N'.
13+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
=== /a.d.ts ===
2+
declare global { namespace N {} }
3+
>global : Symbol(global, Decl(a.d.ts, 0, 0))
4+
>N : Symbol(N, Decl(a.d.ts, 0, 16))
5+
6+
export = N;
7+
>N : Symbol(N, Decl(a.d.ts, 0, 16))
8+
9+
export as namespace N;
10+
>N : Symbol(N, Decl(a.d.ts, 1, 11))
11+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
=== /a.d.ts ===
2+
declare global { namespace N {} }
3+
>global : any
4+
5+
export = N;
6+
>N : any
7+
8+
export as namespace N;
9+
>N : any
10+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// @Filename: /a.d.ts
2+
declare global { namespace N {} }
3+
export = N;
4+
export as namespace N;

0 commit comments

Comments
 (0)