Skip to content

Combining jsdoc @this and @param yields invalid .d.ts file #55197

Description

Bug Report

When combining the JSDoc tags @this and @param, TypeScript yields invalid type definitions.

🔎 Search Terms

jsdoc this constructor

🕗 Version & Regression Information

  • Behaviour was wrong in 4.5.
  • Behaviour changed in 4.6, but is also wrong. This behaviour still exists in 5.2.0-dev.20230729.

⏯ Playground Link

Playground link with relevant code

💻 Code

/** * @typedef Person * @property {string} name *//** * @this {Person} * @param {string} name */exportdefaultfunctionfn(name){this.name=name}

🙁 Actual behavior

/** * @typedef Person * @property {string} name *//** * @this {Person} * @param {string} name */exportdefaultfunctionfn(this: Person,name: string): void;exportdefaultclassfn{/** * @typedef Person * @property {string} name *//** * @this {Person} * @param {string} name */constructor(this: Person,name: string);// ^^^^^^^^^^^^ This is not valid TypeScriptname: string;}exporttypePerson={name: string;};

TypeScript 4.5 and before (also wrong):

/** * @typedef Person * @property {string} name *//** * @this {Person} * @param {string} name */exportdefaultfunctionfn(name: string): void;// ^^ Missing thisexportdefaultclassfn{/** * @typedef Person * @property {string} name *//** * @this {Person} * @param {string} name */constructor(name: string);name: string;}exporttypePerson={name: string;};

🙂 Expected behavior

I would expect the class to not be generated. The generated class definition is the part that is invalid, and also if this function was written in TypeScript, the class would not be generated.

/** * @typedef Person * @property {string} name *//** * @this {Person} * @param {string} name */exportdefaultfunctionfn(this: Person,name: string): void;exporttypePerson={name: string;};

Metadata

Metadata

Labels

Needs InvestigationThis issue needs a team member to investigate its status.RescheduledThis issue was previously scheduled to an earlier milestone

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions