🔍 Search Terms
"ReturnType","generic method"
✅ Viability Checklist
⭐ Suggestion
Given the following types :
typeX=<T>()=>Z<T>;// ortypeX2<Y>=<T>(param: Y)=>Z<T>;
I suggest we should be able to give a generic type parameter to the types :
typeXstr=X<string>;// Xstr = <string>() => Z<string>// ortypeX2str<Y>=X2<Y><string>;// X2str<Y> = <string>(param: Y) => Z<string>
📃 Motivating Example
When having classes with a generic method :
classKlass{method<T>(): Z<T>{ ... }}We can get the method as : type X = Klass["method"] which would be type X = <T>() => Z<T>.
However, to my knowledge, there are currently no ways to get the return type like :
typeReturn<T>=ReturnType<Klass["method"]<T>>;// expected : Return<T> = Z<T>// currently gives an error : "; expected"
We can only do :
typeReturn=ReturnType<Klass["method"]>;// Return = Z<unknown>
However, it is possible to do :
typeX=Klass["method"]>;lettmp: X={}asany;// h4ck for the demonstrationtypeReturn<T>=ReturnType<typeoftmp<T>>;// Return<T> = Z<T>💻 Use Cases
- What do you want to use this for?
Get the returned type of a generic method.
- What shortcomings exist with current approaches?
There are no current approaches to my knowledge.
- What workarounds are you using in the meantime?
Couldn't find any. If you find some, I'm interested.
🔍 Search Terms
"ReturnType","generic method"
✅ Viability Checklist
⭐ Suggestion
Given the following types :
I suggest we should be able to give a generic type parameter to the types :
📃 Motivating Example
When having classes with a generic method :
We can get the method as :
type X = Klass["method"]which would betype X = <T>() => Z<T>.However, to my knowledge, there are currently no ways to get the return type like :
We can only do :
However, it is possible to do :
💻 Use Cases
Get the returned type of a generic method.
There are no current approaches to my knowledge.
Couldn't find any. If you find some, I'm interested.