microsoft / microsoft/TypeScript
Class generics not evaluated properly in JSDoc
@sandersn ci sta già lavorando.
Dal 5/12/2023.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.4k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
🔎 Search Terms
jsdoc generics
🕗 Version & Regression Information
This is the behavior in every version I tried (i.e. at random from 3.6.3 to nightly), and I reviewed the FAQ for entries about jsdoc and generics
⏯ Playground Link
💻 Code
(not working): TypeScript in JSDoc (playground link)
/** @template T */
class Dom {
/** @type {Object<string, T>} */
nodesById = {};
getChildren() {return this.nodesById}
}
/** @type {Dom<number>} */
const node = new Dom();
const children = node.getChildren(); // type is {[id: string]: T}
(working): TypeScript (playground link)
class Dom<T> {
nodesById: {[id: string]: T} = {};
getChildren() {return this.nodesById}
}
const node = new Dom<number>();
const children = node.getChildren(); // type is {[id: string]: number}
🙁 Actual behavior
With TypeScript in JSDoc, children has the type {[id: string]: T}, i.e. T is not resolved, although node has the type Dom<number>.
🙂 Expected behavior
With TypeScript, children has the type {[id: string]: number}, i.e. T is taken correctly from Dom<number>. The same is expected for TypeScript in JSDoc.
Additional information about the issue
Obviously, this is just a minimal working example. We have a large legacy codebase where we introduce TypeScript gradually via JSDoc comments (a nuke-everything TypeScript rewrite would not be feasible).
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Valutazione
Questa issue non è ancora stata valutata.