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

Đang mở
#60,113 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
38/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
javascript, typescript
Lĩnh vực
compilers

Hướng nghiên cứu

Bắt đầu với reproducer được liên kết bằng cách checkout issue-typescript-missing-type-param, chạy npm install và npm run build, sau đó kiểm tra dist/index.d.ts. Truy vết đường dẫn phát sinh khai báo cho một member expression JSDoc @extends; hoàn tất khi mệnh đề extends được sinh ra vẫn giữ đối số kiểu T và khai báo được xác thực.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Bug Domain: JSDoc Help Wanted
🔎 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

Ngôn ngữ chính
Go
Star
111k
Fork
14.4k
Merge trung bình
1 ngày 19 giờ
Pull request đã merge (30 ngày)
117

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của microsoft/TypeScript

Tất cả issue của microsoft/TypeScript

Issue tương tự

Thêm issue về Go

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.