Skip to content

How to type a reusable resolver in Typescript #1719

Answered by kettanaito
javipuche asked this question in Q&A
Discussion options

You must be logged in to vote

Hi, @javipuche. Thanks for raising this.

Getting to know ResponseResolver better

Take a look at the ResponseResolver type:

export type ResponseResolver<
RequestType = MockedRequest,
ContextType = typeof defaultContext,
BodyType extends DefaultBodyType = any,
> = (
req: RequestType,
res: ResponseComposition<BodyType>,
context: ContextType,
) => AsyncResponseResolverReturnType<MockedResponse<BodyType>>

It accepts three generics:

  • RequestType, this is the type for the req provided to the response resolver function.
  • ContextType, the type of the ctx object.
  • BodyType, the response

Replies: 1 comment 1 reply

Comment options

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

Answer selected by kettanaito
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