Skip to content

[TypeScript] Utility type for getting the ResultType from a query function #10403

Answered by italodeandra
italodeandra asked this question in Q&A
Discussion options

You must be logged in to vote

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: Await<ReturnType<Model<User>[Method]>>.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@vkarpov15
Comment options

Answer selected by italodeandra
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants