When I used jsdoc into vscode. I saw I could use typescript utility types. For example:
/**
* Func 1
* @param {number} x
*/
function func1(x) {
return [x, x]
}
/**
* Func 2
* @param {ReturnType<func1>} x // Here !
*/
function func2(x) {
return x[0];
}
So I wonder if this is a correct usage of jsodc. And if there is a way to create my own type transformers, e.g. create one to unwrap promise resolve type.
To create new a type transformer which unwrap promise :
/**
* @template T
* @typedef {T extends Promise<infer Value> ? Value : T} PromiseValue
*/
Or with type-fest :
/**
* @template T
* @typedef {import('type-fest').PromiseValue<T>} PromiseValue
*/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With