Skip to content

Commit 12edac0

Browse files
ajafffsandersn
authored andcommitted
getEffectiveBaseTypeNode: only use JSDoc augments if there is extends (#29349)
1 parent 7c09657 commit 12edac0

4 files changed

Lines changed: 21 additions & 7 deletions

File tree

src/compiler/utilities.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2514,14 +2514,15 @@ namespace ts {
25142514
}
25152515

25162516
export function getEffectiveBaseTypeNode(node: ClassLikeDeclaration | InterfaceDeclaration) {
2517-
if (isInJSFile(node)) {
2517+
const baseType = getClassExtendsHeritageElement(node);
2518+
if (baseType && isInJSFile(node)) {
25182519
// Prefer an @augments tag because it may have type parameters.
25192520
const tag = getJSDocAugmentsTag(node);
25202521
if (tag) {
25212522
return tag.class;
25222523
}
25232524
}
2524-
return getClassExtendsHeritageElement(node);
2525+
return baseType;
25252526
}
25262527

25272528
export function getClassExtendsHeritageElement(node: ClassLikeDeclaration | InterfaceDeclaration) {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/b.js(6,21): error TS2339: Property 'x' does not exist on type 'B'.
2+
3+
4+
==== /b.js (1 errors) ====
5+
class A { constructor() { this.x = 0; } }
6+
7+
/** @augments A */
8+
class B {
9+
m() {
10+
return this.x;
11+
~
12+
!!! error TS2339: Property 'x' does not exist on type 'B'.
13+
}
14+
}
15+

tests/baselines/reference/jsdocAugments_noExtends.symbols

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ class B {
1313
>m : Symbol(B.m, Decl(b.js, 3, 9))
1414

1515
return this.x;
16-
>this.x : Symbol(A.x, Decl(b.js, 0, 25))
1716
>this : Symbol(B, Decl(b.js, 0, 41))
18-
>x : Symbol(A.x, Decl(b.js, 0, 25))
1917
}
2018
}
2119

tests/baselines/reference/jsdocAugments_noExtends.types

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ class B {
1212
>B : B
1313

1414
m() {
15-
>m : () => number
15+
>m : () => any
1616

1717
return this.x;
18-
>this.x : number
18+
>this.x : any
1919
>this : this
20-
>x : number
20+
>x : any
2121
}
2222
}
2323

0 commit comments

Comments
 (0)