diff --git a/src/node/SetupServerApi.ts b/src/node/SetupServerApi.ts index a523ba3e..9cce1043 100644 --- a/src/node/SetupServerApi.ts +++ b/src/node/SetupServerApi.ts @@ -60,10 +60,10 @@ export class SetupServerApi this.handlersController = new AsyncHandlersController(handlers) } - public boundary) => unknown>( - callback: Fn, - ): (...args: Parameters) => ReturnType { - return (...args: Parameters): ReturnType => { + public boundary, R>( + callback: (...args: Args) => R, + ): (...args: Args) => R { + return (...args: Args): R => { return store.run( { initialHandlers: this.handlersController.currentHandlers(), diff --git a/src/node/glossary.ts b/src/node/glossary.ts index 57a576ce..895418d8 100644 --- a/src/node/glossary.ts +++ b/src/node/glossary.ts @@ -70,7 +70,7 @@ export interface SetupServer extends SetupServerCommon { * * @see {@link https://mswjs.io/docs/api/setup-server/boundary `server.boundary()` API reference} */ - boundary) => unknown>( - callback: Fn, - ): (...args: Parameters) => ReturnType + boundary, R>( + callback: (...args: Args) => R, + ): (...args: Args) => R } diff --git a/test/typings/server.boundary.test-d.ts b/test/typings/server.boundary.test-d.ts new file mode 100644 index 00000000..adc273bb --- /dev/null +++ b/test/typings/server.boundary.test-d.ts @@ -0,0 +1,27 @@ +import { setupServer } from 'msw/node' +import { test } from 'vitest' + +const fn = (_args: { a: number }): string => 'hello' + +const server = setupServer() +const bound = server.boundary(fn) + +bound({ a: 1 }).toUpperCase() + +bound({ + // @ts-expect-error Expected number, got string. + a: '1', +}) + +bound({ a: 1 }) + // @ts-expect-error Unknown method ".fooBar()" on string. + .fooBar() + +test( + 'should work', + server.boundary(({ expect }) => { + expect(true).toBe(true) + // @ts-expect-error Property 'doesntExist' does not exist on type 'ExpectStatic' + expect.doesntExist + }), +)