From 786ddfb79b4f67b26e4ed00d9f00f3ac441cfc4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Wed, 16 Jul 2025 00:30:11 +0200 Subject: [PATCH] Don't inherit JSDocs from unrelated base properties onto constructor parameters with the same names --- src/services/services.ts | 3 ++- ...nheritFromSameNamedPropertyOnParameter1.ts | 21 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/jsDocDontInheritFromSameNamedPropertyOnParameter1.ts diff --git a/src/services/services.ts b/src/services/services.ts index 2df3b75ae6cb7..b17e761efe92e 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -121,6 +121,7 @@ import { getSnapshotText, getSourceFileOfNode, getSourceMapper, + getSyntacticModifierFlags, getTokenPosOfNode, getTouchingPropertyName, getTouchingToken, @@ -1051,7 +1052,7 @@ function getDocumentationComment(declarations: readonly Declaration[] | undefine } function findBaseOfDeclaration(checker: TypeChecker, declaration: Declaration, cb: (symbol: Symbol) => T[] | undefined): T[] | undefined { - const classOrInterfaceDeclaration = declaration.parent?.kind === SyntaxKind.Constructor ? declaration.parent.parent : declaration.parent; + const classOrInterfaceDeclaration = declaration.parent?.kind === SyntaxKind.Constructor && getSyntacticModifierFlags(declaration) & ModifierFlags.AccessibilityModifier ? declaration.parent.parent : declaration.parent; if (!classOrInterfaceDeclaration) return; const isStaticMember = hasStaticModifier(declaration); diff --git a/tests/cases/fourslash/jsDocDontInheritFromSameNamedPropertyOnParameter1.ts b/tests/cases/fourslash/jsDocDontInheritFromSameNamedPropertyOnParameter1.ts new file mode 100644 index 0000000000000..93d6eacf50e60 --- /dev/null +++ b/tests/cases/fourslash/jsDocDontInheritFromSameNamedPropertyOnParameter1.ts @@ -0,0 +1,21 @@ +/// + +// https://github.com/microsoft/TypeScript/issues/62069 + +//// class Base { +//// /** +//// * This is a description of `someField` in the `Base` class. +//// * +//// * @deprecated +//// */ +//// someField: string = "whatever"; +//// } +//// +//// class Derived extends Base { +//// constructor(someField: string) { +//// super(); +//// console.log(someField/*1*/); +//// } +//// } + +verify.quickInfoAt("1", "(parameter) someField: string", undefined);