microsoft / microsoft/TypeScript

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

Ouverte
#55,197 0 commentaires 0 réactions 1 personne assignée Voir sur GitHub

@sandersn y travaille déjà.

Depuis le 2/8/2023.

Needs Investigation Rescheduled
Langage dominant
Go
Étoiles
111k
Forks
14.4k
Merge moyen
1 j 19 h
PR mergées (30 j)
117

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
 */
export default function fn(name) {
  this.name = name
}
🙁 Actual behavior
/**
 * @typedef Person
 * @property {string} name
 */
/**
 * @this {Person}
 * @param {string} name
 */
export default function fn(this: Person, name: string): void;
export default class fn {
    /**
     * @typedef Person
     * @property {string} name
     */
    /**
     * @this {Person}
     * @param {string} name
     */
    constructor(this: Person, name: string);
    //          ^^^^^^^^^^^^ This is not valid TypeScript
    name: string;
}
export type Person = {
    name: string;
};

TypeScript 4.5 and before (also wrong):

/**
 * @typedef Person
 * @property {string} name
 */
/**
 * @this {Person}
 * @param {string} name
 */
export default function fn(name: string): void;
//                        ^^ Missing this
export default class fn {
    /**
     * @typedef Person
     * @property {string} name
     */
    /**
     * @this {Person}
     * @param {string} name
     */
    constructor(name: string);
    name: string;
}
export type Person = {
    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
 */
export default function fn(this: Person, name: string): void;
export type Person = {
    name: string;
};

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.