I have a project where I'm using JSDoc to annotate types and typescript definition files to create those types more comfortably. I am porting some generic types from JSDoc to typescript, because it is easier to write. I found that I can not assign a generic type directly to a variable because it says that I must provide the type arguments. So, if I try to do this:
/*
* @type {import('./api').WithDb}
*/
const withDb = handler => async args => {
It fails because WithDb requires two arguments, but this is exactly what I want, to say that this is a generic function.
JSDoc allows you to define generic types using the @template syntax so I can re-annotate the function like this:
/*
* @template T
* @template K
* @type {import('./api').WithDb<T,K>}
*/
const withDb = handler => async args => {
OR
/*
* @template T,K
* @type {import('./api').WithDb<T,K>}
*/
const withDb = handler => async args => {
But it is a lot of boilerplate that I would like to avoid. Is it any other way to bind the types other than @type ?