IssueRaiser

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

Raise real-world problems, find people facing the same issue, and discuss solutions.4,000 issues0 comments

github (Software)

Allow to explicitly pass type parameters via JSDoc

ifeltsweetSep 27, 2018, 12:37 PM

## 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.

Comment on this issue