microsoft / microsoft/TypeScript

JSDoc with @extends, type parameter and member expression gives wrong dts output

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

まだ誰も着手していません。

Bug Domain: JSDoc Help Wanted
主要言語
Go
スター
111k
フォーク
14.4k
平均マージ
1日 19時間
マージ済み PR(30日)
117

説明

🔎 Search Terms

jsdoc type parameter generics extends superclass template

🕗 Version & Regression Information
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about JSDoc type parameters with @extends

I tried with TypeScript 5.0.0, 5.6.2, and 5.7.0-dev.20241001.

⏯ Minimal repro link

I needed more than one file to reproduce, which I can't do on the playground. Here's a simple reproducer:

https://github.com/blutorange/issue-repro/tree/issue-typescript-missing-type-param

git clone https://github.com/blutorange/issue-repro
cd issue-repro
git checkout issue-typescript-missing-type-param
npm install
npm run build

Then open dist/index.d.ts.

💻 Code
/**
 * @template {0|1|2} T
 * @extends {Scope.sub.Box<T>}
 */
export class MyComponent extends Scope.sub.Box {
    more() {
        return "foo";
    }
}
🙁 Actual behavior

The class in the extends clause is missing the type parameter. This is a compile error when you validate the .d.ts file.

declare const MyComponent_base: typeof import("./header.js").Box;
/**
 * @template {0|1|2} T
 * @extends {Scope.sub.Box<T>}
 */
export class MyComponent<T extends 0 | 1 | 2> extends MyComponent_base {
    constructor();
    more(): string;
}
export {};
🙂 Expected behavior

TypeScript should include the type parameter in the extends clause.

declare const MyComponent_base: typeof import("./header.js").Box;
/**
 * @template {0|1|2} T
 * @extends {Scope.sub.Box<T>}
 */
export class MyComponent<T extends 0 | 1 | 2> extends MyComponent_base<T> {
    constructor();
    more(): string;
}
export {};
Additional information about the issue

Only seems to happen when the extends clause is a member expression where TS generate an intermediate declare const ....

Fyi, I came across this issue while investigating how to setup a project for generating type declarations from js files for primefaces/primefaces#12500

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

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

はじめの一歩

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

調査の方向性

リンクされた再現ケースから始め、issue-typescript-missing-type-param をチェックアウトし、npm install と npm run build を実行してから、dist/index.d.ts を調べます。JSDoc @extends の member expression に対する宣言出力の経路を追跡します。生成された extends 句が T 型引数を保持し、宣言が有効であることを確認できれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
javascript, typescript
領域
compilers
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
38/100

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

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