Question
Is there a general way to implement a generic type that takes a type T
and a generic type G<>
and outputs the former passed into the latter G<T>
?
Goal
/**
* @template G, T
* @typedef {G<T>} Transform<G,T>
*/
/**
* @typedef {Transform<Array, string>} StringArray
* @typedef {Transform<Promise, string>} StringPromise
*/
This doesn't seem to work unfortunately.
Limited functionality
What does work is this, but it needs the possible generic types to be specified.
/**
* @template G, T
* @typedef {G extends Promise ? Promise<T> : G extends Array ? Array<T> : unkown } Transform<G,T>
*/
/**
* @typedef {Transform<Array, string>} StringArray
* @typedef {Transform<Promise, string>} StringPromise
*/