From 306a0723e0eee6c14972e04eb8aa132e052f0246 Mon Sep 17 00:00:00 2001 From: Klaus Meinhardt Date: Thu, 10 Jan 2019 17:48:03 +0100 Subject: [PATCH] getEffectiveBaseTypeNode: only use JSDoc augments if there is extends --- src/compiler/utilities.ts | 5 +++-- .../reference/jsdocAugments_noExtends.errors.txt | 15 +++++++++++++++ .../reference/jsdocAugments_noExtends.symbols | 2 -- .../reference/jsdocAugments_noExtends.types | 6 +++--- 4 files changed, 21 insertions(+), 7 deletions(-) create mode 100644 tests/baselines/reference/jsdocAugments_noExtends.errors.txt diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 9c6b27de13cce..b23ec69f2d40d 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -2513,14 +2513,15 @@ namespace ts { } export function getEffectiveBaseTypeNode(node: ClassLikeDeclaration | InterfaceDeclaration) { - if (isInJSFile(node)) { + const baseType = getClassExtendsHeritageElement(node); + if (baseType && isInJSFile(node)) { // Prefer an @augments tag because it may have type parameters. const tag = getJSDocAugmentsTag(node); if (tag) { return tag.class; } } - return getClassExtendsHeritageElement(node); + return baseType; } export function getClassExtendsHeritageElement(node: ClassLikeDeclaration | InterfaceDeclaration) { diff --git a/tests/baselines/reference/jsdocAugments_noExtends.errors.txt b/tests/baselines/reference/jsdocAugments_noExtends.errors.txt new file mode 100644 index 0000000000000..036f30301f921 --- /dev/null +++ b/tests/baselines/reference/jsdocAugments_noExtends.errors.txt @@ -0,0 +1,15 @@ +/b.js(6,21): error TS2339: Property 'x' does not exist on type 'B'. + + +==== /b.js (1 errors) ==== + class A { constructor() { this.x = 0; } } + + /** @augments A */ + class B { + m() { + return this.x; + ~ +!!! error TS2339: Property 'x' does not exist on type 'B'. + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/jsdocAugments_noExtends.symbols b/tests/baselines/reference/jsdocAugments_noExtends.symbols index cd3d8575f26c9..2303e6009791c 100644 --- a/tests/baselines/reference/jsdocAugments_noExtends.symbols +++ b/tests/baselines/reference/jsdocAugments_noExtends.symbols @@ -13,9 +13,7 @@ class B { >m : Symbol(B.m, Decl(b.js, 3, 9)) return this.x; ->this.x : Symbol(A.x, Decl(b.js, 0, 25)) >this : Symbol(B, Decl(b.js, 0, 41)) ->x : Symbol(A.x, Decl(b.js, 0, 25)) } } diff --git a/tests/baselines/reference/jsdocAugments_noExtends.types b/tests/baselines/reference/jsdocAugments_noExtends.types index 5a2c5632ab700..fab9c7b7c84e8 100644 --- a/tests/baselines/reference/jsdocAugments_noExtends.types +++ b/tests/baselines/reference/jsdocAugments_noExtends.types @@ -12,12 +12,12 @@ class B { >B : B m() { ->m : () => number +>m : () => any return this.x; ->this.x : number +>this.x : any >this : this ->x : number +>x : any } }