Skip to content

Commit

Permalink
update usage with typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
kettanaito committed Jan 17, 2024
1 parent b743612 commit a84d71e
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/content/docs/best-practices/typescript.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ graphql.mutation<AddCommentQuery, AddCommentVariables>(
commentUrl: `/post/${postId}?commentId=${crypto.randomUUID()}`,
},
})
},
}
)
```

Expand All @@ -121,7 +121,7 @@ graphql.mutation<AddCommentQuery, AddCommentVariables>(
Use the `HttpHandler` and `GraphQLHandler` types to annotate higher-order request handlers.

```ts
import { HttpHandler, HttpResponseResolver, http, HttpResponse } from 'msw'
import { http, HttpResponseResolver, HttpResponse } from 'msw'

type SdkRequest = {
transactionId: string
Expand All @@ -133,8 +133,8 @@ type SdkResponse = {
}

function handleSdkRequest(
resolver: HttpResponseResolver,
): HttpHandler<never, SdkRequest, SdkResponse> {
resolver: HttpResponseResolver<never, SdkRequest, SdkResponse>
) {
return http.post('https://some-sdk.com/internal/request', resolver)
}

Expand Down Expand Up @@ -173,7 +173,7 @@ function withDelay<
// so the arguments passed to "http.get" propagate here.
Params extends PathParams,
RequestBodyType extends DefaultBodyType,
ResponseBodyType extends DefaultBodyType,
ResponseBodyType extends DefaultBodyType
>(durationMs: number, resolver: HttpResponseResolver): HttpResponseResolver {
return async (...args) => {
await delay(durationMs)
Expand All @@ -189,7 +189,7 @@ export const handlers = [
// to the "http.get()" request handler propagates
// through the custom "withDelay" response resolver.
return HttpResponse.text('hello world')
}),
})
),
]
```

0 comments on commit a84d71e

Please sign in to comment.