How to type a reusable resolver in Typescript #1719
-
Hello, I have some questions about typing when using a reusable resolver. Is it something like this?: import type { ResponseResolver } from 'msw'
export const mockUser: ResponseResolver = (req, res, ctx) => {
return res(
ctx.json({
firstName: 'John',
age: 38,
}),
)
} This show an error in Or maybe, Is it something like this? (I don't know what to use for "res" in this case): import type { RestContext, RestRequest } from 'msw'
export const mockUser = (req: RestRequest, res, ctx: RestContext) => {
return res(
ctx.json({
firstName: 'John',
age: 38,
}),
)
} Thank you for clearing up my doubts |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi, @javipuche. Thanks for raising this. Getting to know
|
Beta Was this translation helpful? Give feedback.
Hi, @javipuche. Thanks for raising this.
Getting to know
ResponseResolver
betterTake a look at the
ResponseResolver
type:msw/src/handlers/RequestHandler.ts
Lines 73 to 81 in ad27719
It accepts three generics:
RequestType
, this is the type for thereq
provided to the response resolver function.ContextType
, the type of thectx
object.BodyType
, the response