Allow to explicitly pass type parameters via JSDoc
## Search Terms jsdoc generics type parameters constraints ## Suggestion It seems like it is not possible via JSDoc to explicitly tell compiler which type parameters to pass to a generic function. ## Use Cases In TypeScript it is possible to explicitly pass type parameters such as `mongoose.model<Model, Schema>('modelName', Schema)` while I could not find a way to do same with JSDoc. ## Examples `mongoose.model` has two signatures, first one with one type parameter and the other with two. To make use of the second signature we must pass types explicitly. ```ts export function model<T extends Document>( name: string, schema?: Schema, collection?: string, skipInit?: boolean ): Model<T>; export function model<T extends Document, U extends Model<T>>( name: string, schema?: Schema, collection?: string, skipInit?: boolean ): U; ``` ```ts // Choose second signature in typescript. const model = mongoose.model<Model, Schema>('modelName', Schema); // With JSDoc, compiler always chooses first signature and we receive a type mismatch error. /** @type {Schema & mongoose.Model<Model>} */ const model = mongoose.model('modelName', Schema); // But something like this would be great. const model = mongoose.model/**<Model, Schema>*/('modelName', Schema); ``` My apologies if this is already possible, but I've spend almost a week battling this. Related: https://github.com/Microsoft/TypeScript-Node-Starter/issues/101 ## Checklist My suggestion meets these guidelines
Posted by ifeltsweet on Sep 27, 2018, 12:37 PM
Tags
Related issues
- [Meta] Feedback on granular control over Copilot changes
- unexpected status 401 Unauthorized issue
- [MODEL] Measurable quality regression in Claude generation 5 (Fable 5 / Opus 5 / Sonnet 5): worse nonsense detection, ~2x verbosity, under-disclosed model fallb
- [CRITICAL] Subagent spawning and subagent pattern bugs trigger infinite recursion, infinite token usage, grossly inefficient token usage, and lost accumulated s
- Video stops playing after some minutes
- [MODEL] Claude verbose code comments by default — ignores instructions to stop.
Raise real-world problems, find people facing the same issue, and discuss solutions.4,000 issues0 comments
github (Software)
[Meta] Feedback on granular control over Copilot changes
unexpected status 401 Unauthorized issue
[MODEL] Measurable quality regression in Claude generation 5 (Fable 5 / Opus 5 / Sonnet 5): worse nonsense detection, ~2x verbosity, under-disclosed model fallb
[CRITICAL] Subagent spawning and subagent pattern bugs trigger infinite recursion, infinite token usage, grossly inefficient token usage, and lost accumulated s
Video stops playing after some minutes
[MODEL] Claude verbose code comments by default — ignores instructions to stop.
Scope Codex VS Code chats to the current workspace/project
Update on "Co-authored-by: Copilot" in commit messages
Allow to explicitly pass type parameters via JSDoc
## Search Terms jsdoc generics type parameters constraints ## Suggestion It seems like it is not possible via JSDoc to explicitly tell compiler which type parameters to pass to a generic function. ## Use Cases In TypeScript it is possible to explicitly pass type parameters such as `mongoose.model<Model, Schema>('modelName', Schema)` while I could not find a way to do same with JSDoc. ## Examples `mongoose.model` has two signatures, first one with one type parameter and the other with two. To make use of the second signature we must pass types explicitly. ```ts export function model<T extends Document>( name: string, schema?: Schema, collection?: string, skipInit?: boolean ): Model<T>; export function model<T extends Document, U extends Model<T>>( name: string, schema?: Schema, collection?: string, skipInit?: boolean ): U; ``` ```ts // Choose second signature in typescript. const model = mongoose.model<Model, Schema>('modelName', Schema); // With JSDoc, compiler always chooses first signature and we receive a type mismatch error. /** @type {Schema & mongoose.Model<Model>} */ const model = mongoose.model('modelName', Schema); // But something like this would be great. const model = mongoose.model/**<Model, Schema>*/('modelName', Schema); ``` My apologies if this is already possible, but I've spend almost a week battling this. Related: https://github.com/Microsoft/TypeScript-Node-Starter/issues/101 ## Checklist My suggestion meets these guidelines
Comments (0)
No comments yet. Start the discussion.