From c7bab818f789ef5755ca8868e13c0561eb5035c1 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Sat, 13 Nov 2021 11:08:47 +0200 Subject: [PATCH] fix(44693): emit declaration of JSDoc overridden properties with different types --- src/compiler/checker.ts | 2 +- .../reference/jsDeclarationsInheritedTypes.js | 64 +++++++++++++++++++ .../jsDeclarationsInheritedTypes.symbols | 43 +++++++++++++ .../jsDeclarationsInheritedTypes.types | 43 +++++++++++++ .../compiler/jsDeclarationsInheritedTypes.ts | 37 +++++++++++ 5 files changed, 188 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/jsDeclarationsInheritedTypes.js create mode 100644 tests/baselines/reference/jsDeclarationsInheritedTypes.symbols create mode 100644 tests/baselines/reference/jsDeclarationsInheritedTypes.types create mode 100644 tests/cases/compiler/jsDeclarationsInheritedTypes.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 0dd0d1d6b4f3e..cd59bf86aeef8 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -39048,7 +39048,7 @@ namespace ts { const properties = getPropertiesOfType(getTypeWithThisArgument(base, type.thisType)); for (const prop of properties) { const existing = seen.get(prop.escapedName); - if (existing && !isPropertyIdenticalTo(existing, prop)) { + if (existing && prop.parent === existing.parent) { seen.delete(prop.escapedName); } } diff --git a/tests/baselines/reference/jsDeclarationsInheritedTypes.js b/tests/baselines/reference/jsDeclarationsInheritedTypes.js new file mode 100644 index 0000000000000..5fce213976ef2 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsInheritedTypes.js @@ -0,0 +1,64 @@ +//// [a.js] +/** + * @typedef A + * @property {string} a + */ + +/** + * @typedef B + * @property {number} b + */ + + class C1 { + /** + * @type {A} + */ + value; +} + +class C2 extends C1 { + /** + * @type {A} + */ + value; +} + +class C3 extends C1 { + /** + * @type {A & B} + */ + value; +} + + + + +//// [a.d.ts] +/** + * @typedef A + * @property {string} a + */ +/** + * @typedef B + * @property {number} b + */ +declare class C1 { + /** + * @type {A} + */ + value: A; +} +declare class C2 extends C1 { +} +declare class C3 extends C1 { + /** + * @type {A & B} + */ + value: A & B; +} +type A = { + a: string; +}; +type B = { + b: number; +}; diff --git a/tests/baselines/reference/jsDeclarationsInheritedTypes.symbols b/tests/baselines/reference/jsDeclarationsInheritedTypes.symbols new file mode 100644 index 0000000000000..b649cacc669f7 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsInheritedTypes.symbols @@ -0,0 +1,43 @@ +=== tests/cases/compiler/a.js === +/** + * @typedef A + * @property {string} a + */ + +/** + * @typedef B + * @property {number} b + */ + + class C1 { +>C1 : Symbol(C1, Decl(a.js, 0, 0)) + + /** + * @type {A} + */ + value; +>value : Symbol(C1.value, Decl(a.js, 10, 11)) +} + +class C2 extends C1 { +>C2 : Symbol(C2, Decl(a.js, 15, 1)) +>C1 : Symbol(C1, Decl(a.js, 0, 0)) + + /** + * @type {A} + */ + value; +>value : Symbol(C2.value, Decl(a.js, 17, 21)) +} + +class C3 extends C1 { +>C3 : Symbol(C3, Decl(a.js, 22, 1)) +>C1 : Symbol(C1, Decl(a.js, 0, 0)) + + /** + * @type {A & B} + */ + value; +>value : Symbol(C3.value, Decl(a.js, 24, 21)) +} + diff --git a/tests/baselines/reference/jsDeclarationsInheritedTypes.types b/tests/baselines/reference/jsDeclarationsInheritedTypes.types new file mode 100644 index 0000000000000..9898379887ee6 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsInheritedTypes.types @@ -0,0 +1,43 @@ +=== tests/cases/compiler/a.js === +/** + * @typedef A + * @property {string} a + */ + +/** + * @typedef B + * @property {number} b + */ + + class C1 { +>C1 : C1 + + /** + * @type {A} + */ + value; +>value : A +} + +class C2 extends C1 { +>C2 : C2 +>C1 : C1 + + /** + * @type {A} + */ + value; +>value : A +} + +class C3 extends C1 { +>C3 : C3 +>C1 : C1 + + /** + * @type {A & B} + */ + value; +>value : A & B +} + diff --git a/tests/cases/compiler/jsDeclarationsInheritedTypes.ts b/tests/cases/compiler/jsDeclarationsInheritedTypes.ts new file mode 100644 index 0000000000000..303d3ba9bacd4 --- /dev/null +++ b/tests/cases/compiler/jsDeclarationsInheritedTypes.ts @@ -0,0 +1,37 @@ +// @checkJs: true +// @allowJs: true +// @declaration: true +// @emitDeclarationOnly: true +// @outDir: ./dist +// @filename: a.js + +/** + * @typedef A + * @property {string} a + */ + +/** + * @typedef B + * @property {number} b + */ + + class C1 { + /** + * @type {A} + */ + value; +} + +class C2 extends C1 { + /** + * @type {A} + */ + value; +} + +class C3 extends C1 { + /** + * @type {A & B} + */ + value; +}