Type error using default RequestHandler
type
#498
-
Hey guys, I've set up Everything is working flawlessly but I have a TypeScript error that I can't get rid off without using Here is my code:
And this is the TypeScript error that I get:
By overcharging with
Is there a way to achieve this without Thanks for your time 🙏 |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hi @Erazihel thanks for reaching us :). You can do in this way import {
rest,
RequestHandler,
MockedRequest,
RequestParams,
restContext,
ParsedRestRequest,
} from 'msw'
export function handleCourse(): RequestHandler<
MockedRequest<null, RequestParams>,
typeof restContext,
ParsedRestRequest,
MockedRequest<null>,
string
> {
return rest.get(COURSE_URL, (_, res, ctx) => res(ctx.json({ foo: 'bar' })))
} You can also drop the response type because it will be inferred from the return value export function handleCourse() {
return rest.get(COURSE_URL, (_, res, ctx) => res(ctx.json({ foo: 'bar' })))
} |
Beta Was this translation helpful? Give feedback.
-
I wonder if return type inference would be preferable in this scenario. |
Beta Was this translation helpful? Give feedback.
Hi @Erazihel thanks for reaching us :).
You can do in this way
You can also drop the response type because it will be inferred from the return value