microsoft / microsoft/TypeScript

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

Aperta
#55,197 0 commenti 0 reazioni 1 assegnatario Vedi su GitHub

@sandersn ci sta già lavorando.

Dal 2/8/2023.

Needs Investigation Rescheduled
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

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;
};

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.