🔎 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
https://www.typescriptlang.org/play?ts=5.4.0-dev.20231205&filetype=js#code/PQKhAIAEBcFMFsAOAbAhncAVcJgCgBjNAZ2PABEB7ecAbz3EfFAhgE9FY6B5AIwCtYBaAB5i0AE4BLAHYBzADRYAfAF8c+JuBmUAJrGIAhNgEld4ALx1VAbgZM5saAGEAFlOS6JsGQAoAlHTe0ACuEjLg0O7EAHQ6+kamuqp4KXgsUNAcXLRU8CIyIfC8sBJqGoSUMuLaelxWMrAA7hTUAXYEVTUE7p7eEQ11MY4uvV4+7UA
💻 Code
(not working): TypeScript in JSDoc (playground link)
/** @template T */classDom{/** @type {Object<string, T>} */nodesById={};getChildren(){returnthis.nodesById}}/** @type {Dom<number>} */constnode=newDom();constchildren=node.getChildren();// type is {[id: string]: T}classDom<T>{nodesById: {[id: string]: T}={};getChildren(){returnthis.nodesById}}constnode=newDom<number>();constchildren=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).
🔎 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
https://www.typescriptlang.org/play?ts=5.4.0-dev.20231205&filetype=js#code/PQKhAIAEBcFMFsAOAbAhncAVcJgCgBjNAZ2PABEB7ecAbz3EfFAhgE9FY6B5AIwCtYBaAB5i0AE4BLAHYBzADRYAfAF8c+JuBmUAJrGIAhNgEld4ALx1VAbgZM5saAGEAFlOS6JsGQAoAlHTe0ACuEjLg0O7EAHQ6+kamuqp4KXgsUNAcXLRU8CIyIfC8sBJqGoSUMuLaelxWMrAA7hTUAXYEVTUE7p7eEQ11MY4uvV4+7UA
💻 Code
(not working): TypeScript in JSDoc (playground link)
(working): TypeScript (playground link)
🙁 Actual behavior
With TypeScript in JSDoc,
childrenhas the type{[id: string]: T}, i.e.Tis not resolved, althoughnodehas the typeDom<number>.🙂 Expected behavior
With TypeScript,
childrenhas the type{[id: string]: number}, i.e.Tis taken correctly fromDom<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).