Skip to content

Type error using default RequestHandler type #498

Answered by marcosvega91
Erazihel asked this question in Q&A
Discussion options

You must be logged in to vote

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' })))
}

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by Erazihel
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants