- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.1k
Open
Labels
Needs InvestigationThis issue needs a team member to investigate its status.This issue needs a team member to investigate its status.
Milestone
Description
π 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).
bouzlibop and attekemppila
Metadata
Metadata
Assignees
Labels
Needs InvestigationThis issue needs a team member to investigate its status.This issue needs a team member to investigate its status.