[TypeScript] Utility type for getting the ResultType
from a query function
#10403
-
Actual questionIs there a utility type or a do someone have any suggestions for me to be able to get the I got to this type already: ReturnType<Model<User>[Method]> and this actually translates to Query<(User & Document<any, any>)[], User & Document<any, any>, {}> How do I get only the Small introductionHi team, I'm building an extension of Mongoose which will transform the models you create into API's to be consumed on the frontend (just very oversimplified explanation of what it actually is). The problem of making something in that scale, is that typings are complicated, so that's why I need to make this utility and I'm having some trouble. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I created this utility type which gets the thenable result type Await<T> = T extends {
then(onfulfilled?: (value: infer U) => unknown): unknown
}
? U
: T So this type get's exactly what I want: |
Beta Was this translation helpful? Give feedback.
I created this utility type which gets the thenable result
So this type get's exactly what I want:
Await<ReturnType<Model<User>[Method]>>
.