microsoft / microsoft/TypeScript
JSDoc with @extends, type parameter and member expression gives wrong dts output
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
🔎 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
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit dem verknüpften Reproducer, indem du issue-typescript-missing-type-param auscheckst, npm install und npm run build ausführst und anschließend dist/index.d.ts untersuchst. Verfolge den Pfad der Deklarationserzeugung für einen JSDoc @extends member expression; fertig ist die Aufgabe, wenn die generierte extends-Klausel das T-Typargument beibehält und die Deklaration validiert.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- javascript, typescript
- Bereich
- compilers
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 38/100