diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 6b152ad909dcb..6be419174bdf1 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -14541,8 +14541,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } } - const classType = declaration.kind === SyntaxKind.Constructor ? - getDeclaredTypeOfClassOrInterface(getMergedSymbol((declaration.parent as ClassDeclaration).symbol)) + const hostDeclaration = isJSDocSignature(declaration) ? getEffectiveJSDocHost(declaration) : declaration; + const classType = hostDeclaration && isConstructorDeclaration(hostDeclaration) ? + getDeclaredTypeOfClassOrInterface(getMergedSymbol((hostDeclaration.parent as ClassDeclaration).symbol)) : undefined; const typeParameters = classType ? classType.localTypeParameters : getTypeParametersFromDeclaration(declaration); if (hasRestParameter(declaration) || isInJSFile(declaration) && maybeAddJsSyntheticRestParameter(declaration, parameters)) { diff --git a/tests/baselines/reference/overloadTag3.symbols b/tests/baselines/reference/overloadTag3.symbols new file mode 100644 index 0000000000000..4c59ed907f698 --- /dev/null +++ b/tests/baselines/reference/overloadTag3.symbols @@ -0,0 +1,29 @@ +=== /a.js === +/** + * @template T + */ +export class Foo { +>Foo : Symbol(Foo, Decl(a.js, 0, 0)) + + /** + * @constructor + * @overload + */ + constructor() { } + + /** + * @param {T} value + */ + bar(value) { } +>bar : Symbol(Foo.bar, Decl(a.js, 8, 21)) +>value : Symbol(value, Decl(a.js, 13, 8)) +} + +/** @type {Foo} */ +let foo; +>foo : Symbol(foo, Decl(a.js, 17, 3)) + +foo = new Foo(); +>foo : Symbol(foo, Decl(a.js, 17, 3)) +>Foo : Symbol(Foo, Decl(a.js, 0, 0)) + diff --git a/tests/baselines/reference/overloadTag3.types b/tests/baselines/reference/overloadTag3.types new file mode 100644 index 0000000000000..8ff42674a85e7 --- /dev/null +++ b/tests/baselines/reference/overloadTag3.types @@ -0,0 +1,31 @@ +=== /a.js === +/** + * @template T + */ +export class Foo { +>Foo : Foo + + /** + * @constructor + * @overload + */ + constructor() { } + + /** + * @param {T} value + */ + bar(value) { } +>bar : (value: T) => void +>value : T +} + +/** @type {Foo} */ +let foo; +>foo : Foo + +foo = new Foo(); +>foo = new Foo() : Foo +>foo : Foo +>new Foo() : Foo +>Foo : typeof Foo + diff --git a/tests/cases/conformance/jsdoc/overloadTag3.ts b/tests/cases/conformance/jsdoc/overloadTag3.ts new file mode 100644 index 0000000000000..999184d4263e2 --- /dev/null +++ b/tests/cases/conformance/jsdoc/overloadTag3.ts @@ -0,0 +1,24 @@ +// @checkJs: true +// @allowJs: true +// @strict: true +// @noEmit: true +// @filename: /a.js +/** + * @template T + */ +export class Foo { + /** + * @constructor + * @overload + */ + constructor() { } + + /** + * @param {T} value + */ + bar(value) { } +} + +/** @type {Foo} */ +let foo; +foo = new Foo();