Skip to content

Commit f37101e

Browse files
author
Andy
authored
Fix bug when augmenting parent-less symbol (#28345)
1 parent 4cb210c commit f37101e

File tree

5 files changed

+107
-1
lines changed

5 files changed

+107
-1
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26751,7 +26751,7 @@ namespace ts {
2675126751
let reportError = !(symbol.flags & SymbolFlags.Transient);
2675226752
if (!reportError) {
2675326753
// symbol should not originate in augmentation
26754-
reportError = isExternalModuleAugmentation(symbol.parent!.declarations[0]);
26754+
reportError = !!symbol.parent && isExternalModuleAugmentation(symbol.parent.declarations[0]);
2675526755
}
2675626756
}
2675726757
break;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//// [tests/cases/compiler/moduleAugmentationOfAlias.ts] ////
2+
3+
//// [a.ts]
4+
interface I {}
5+
export default I;
6+
7+
//// [b.ts]
8+
export {};
9+
declare module './a' {
10+
export default interface I { x: number; }
11+
}
12+
13+
//// [c.ts]
14+
import I from "./a";
15+
function f(i: I) {
16+
i.x;
17+
}
18+
19+
20+
//// [a.js]
21+
"use strict";
22+
exports.__esModule = true;
23+
//// [b.js]
24+
"use strict";
25+
exports.__esModule = true;
26+
//// [c.js]
27+
"use strict";
28+
exports.__esModule = true;
29+
function f(i) {
30+
i.x;
31+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
=== /a.ts ===
2+
interface I {}
3+
>I : Symbol(I, Decl(a.ts, 0, 0), Decl(b.ts, 1, 22))
4+
5+
export default I;
6+
>I : Symbol(I, Decl(a.ts, 0, 0))
7+
8+
=== /b.ts ===
9+
export {};
10+
declare module './a' {
11+
>'./a' : Symbol("/a", Decl(a.ts, 0, 0), Decl(b.ts, 0, 10))
12+
13+
export default interface I { x: number; }
14+
>I : Symbol(I, Decl(a.ts, 0, 0), Decl(b.ts, 1, 22))
15+
>x : Symbol(I.x, Decl(b.ts, 2, 32))
16+
}
17+
18+
=== /c.ts ===
19+
import I from "./a";
20+
>I : Symbol(I, Decl(c.ts, 0, 6))
21+
22+
function f(i: I) {
23+
>f : Symbol(f, Decl(c.ts, 0, 20))
24+
>i : Symbol(i, Decl(c.ts, 1, 11))
25+
>I : Symbol(I, Decl(c.ts, 0, 6))
26+
27+
i.x;
28+
>i.x : Symbol(I.x, Decl(b.ts, 2, 32))
29+
>i : Symbol(i, Decl(c.ts, 1, 11))
30+
>x : Symbol(I.x, Decl(b.ts, 2, 32))
31+
}
32+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
=== /a.ts ===
2+
interface I {}
3+
export default I;
4+
>I : I
5+
6+
=== /b.ts ===
7+
export {};
8+
declare module './a' {
9+
>'./a' : typeof import("/a")
10+
11+
export default interface I { x: number; }
12+
>x : number
13+
}
14+
15+
=== /c.ts ===
16+
import I from "./a";
17+
>I : any
18+
19+
function f(i: I) {
20+
>f : (i: I) => void
21+
>i : I
22+
23+
i.x;
24+
>i.x : number
25+
>i : I
26+
>x : number
27+
}
28+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// @Filename: /a.ts
2+
interface I {}
3+
export default I;
4+
5+
// @Filename: /b.ts
6+
export {};
7+
declare module './a' {
8+
export default interface I { x: number; }
9+
}
10+
11+
// @Filename: /c.ts
12+
import I from "./a";
13+
function f(i: I) {
14+
i.x;
15+
}

0 commit comments

Comments
 (0)