Skip to content

Commit 66abcb9

Browse files
author
Andy
authored
Handle undefined symbol.declarations in cloneSymbol (microsoft#18474)
1 parent b934c8b commit 66abcb9

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ namespace ts {
578578

579579
function cloneSymbol(symbol: Symbol): Symbol {
580580
const result = createSymbol(symbol.flags, symbol.escapedName);
581-
result.declarations = symbol.declarations.slice(0);
581+
result.declarations = symbol.declarations ? symbol.declarations.slice() : [];
582582
result.parent = symbol.parent;
583583
if (symbol.valueDeclaration) result.valueDeclaration = symbol.valueDeclaration;
584584
if (symbol.constEnumOnlyModule) result.constEnumOnlyModule = true;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/b.ts(2,15): error TS2300: Duplicate identifier 'prototype'.
2+
3+
4+
==== /a.d.ts (0 errors) ====
5+
declare class Foo {}
6+
7+
==== /b.ts (1 errors) ====
8+
declare namespace Foo {
9+
namespace prototype {
10+
~~~~~~~~~
11+
!!! error TS2300: Duplicate identifier 'prototype'.
12+
function f(): void;
13+
}
14+
}
15+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//// [tests/cases/compiler/mergedClassWithNamespacePrototype.ts] ////
2+
3+
//// [a.d.ts]
4+
declare class Foo {}
5+
6+
//// [b.ts]
7+
declare namespace Foo {
8+
namespace prototype {
9+
function f(): void;
10+
}
11+
}
12+
13+
14+
//// [b.js]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// @Filename: /a.d.ts
2+
declare class Foo {}
3+
4+
// @Filename: /b.ts
5+
declare namespace Foo {
6+
namespace prototype {
7+
function f(): void;
8+
}
9+
}

0 commit comments

Comments
 (0)