microsoft / microsoft/TypeScript

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

オープン
#55,197 コメント 0 件 リアクション 0 件 担当者 1 名 GitHub で見る

@sandersn がすでに取り組んでいます。

2023年8月2日 から。

Needs Investigation Rescheduled
主要言語
Go
スター
111k
フォーク
14.4k
平均マージ
1日 19時間
マージ済み PR(30日)
117

説明

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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。