Skip to content

How to use typescript? #2048

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

You must be logged in to vote

Hi, @qqww08. Here's how you can annotate the resolver argument:

import type { HttpResponseResolver } from 'msw'

export const postLogin = async (resolver: HttpResponseResolver) => {
  // ...your logic here.
}

Learn more about Using MSW with TypeScript.

Based on your usage snippet, I think you are looking for this instead:

export const postLogin: HttpResponseResolver = () => {
  return HttpResponse.json({ data: 'ok' })
}

Then, you can use the postLogin function as a response resolver itself:

http.post('/endpoint', postLogin)

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
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