Skip to content

Commit

Permalink
fix: correctly check "undefined" as response body type (#1824)
Browse files Browse the repository at this point in the history
  • Loading branch information
kettanaito authored Nov 4, 2023
1 parent 66fb437 commit a0ec8be
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/core/handlers/RequestHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export interface RequestHandlerInternalInfo {
export type ResponseResolverReturnType<
BodyType extends DefaultBodyType = undefined,
> =
| (BodyType extends undefined ? Response : StrictResponse<BodyType>)
| ([BodyType] extends [undefined] ? Response : StrictResponse<BodyType>)
| undefined
| void

Expand Down Expand Up @@ -265,7 +265,7 @@ export abstract class RequestHandler<

// Clone the previously stored response from the generator
// so that it could be read again.
return this.resolverGeneratorResult.clone()
return this.resolverGeneratorResult.clone() as StrictResponse<any>
}

if (!this.resolverGenerator) {
Expand Down
10 changes: 10 additions & 0 deletions test/typings/regressions/response-body-type.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* @see https://github.com/mswjs/msw/issues/1823
*/
import { http, Path, HttpResponse, DefaultBodyType } from 'msw'

function myHandler<CustomResponseBodyType extends DefaultBodyType>(path: Path) {
return (response: CustomResponseBodyType) => {
http.get(path, () => HttpResponse.json(response))
}
}

0 comments on commit a0ec8be

Please sign in to comment.