How to use typescript? #2048
-
Hi // mocks/index.ts
import { postLogin } from './postLogin.ts'
http.post(`${baseUrl}/login`, postLogin) // mocks/postLogin.ts
// 🙏I am curious about the type of resolver.
export const postLogin = async (resolver: ❓??) => {
return HttpResponse.json({ data: "ok" }, { status: 200 });
} |
Beta Was this translation helpful? Give feedback.
Answered by
kettanaito
Feb 28, 2024
Replies: 1 comment
-
Hi, @qqww08. Here's how you can annotate the import type { HttpResponseResolver } from 'msw'
export const postLogin = async (resolver: HttpResponseResolver) => {
// ...your logic here.
}
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 http.post('/endpoint', postLogin) |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
kettanaito
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, @qqww08. Here's how you can annotate the
resolver
argument:Based on your usage snippet, I think you are looking for this instead:
Then, you can use the
postLogin
function as a response resolver itself: