File tree 3 files changed +34
-7
lines changed
3 files changed +34
-7
lines changed Original file line number Diff line number Diff line change @@ -60,10 +60,10 @@ export class SetupServerApi
60
60
this . handlersController = new AsyncHandlersController ( handlers )
61
61
}
62
62
63
- public boundary < Fn extends ( ... args : Array < any > ) => unknown > (
64
- callback : Fn ,
65
- ) : ( ...args : Parameters < Fn > ) => ReturnType < Fn > {
66
- return ( ...args : Parameters < Fn > ) : ReturnType < Fn > => {
63
+ public boundary < Args extends Array < any > , R > (
64
+ callback : ( ... args : Args ) => R ,
65
+ ) : ( ...args : Args ) => R {
66
+ return ( ...args : Args ) : R => {
67
67
return store . run < any , any > (
68
68
{
69
69
initialHandlers : this . handlersController . currentHandlers ( ) ,
Original file line number Diff line number Diff line change @@ -70,7 +70,7 @@ export interface SetupServer extends SetupServerCommon {
70
70
*
71
71
* @see {@link https://mswjs.io/docs/api/setup-server/boundary `server.boundary()` API reference }
72
72
*/
73
- boundary < Fn extends ( ... args : Array < any > ) => unknown > (
74
- callback : Fn ,
75
- ) : ( ...args : Parameters < Fn > ) => ReturnType < Fn >
73
+ boundary < Args extends Array < any > , R > (
74
+ callback : ( ... args : Args ) => R ,
75
+ ) : ( ...args : Args ) => R
76
76
}
Original file line number Diff line number Diff line change
1
+ import { setupServer } from 'msw/node'
2
+ import { test } from 'vitest'
3
+
4
+ const fn = ( _args : { a : number } ) : string => 'hello'
5
+
6
+ const server = setupServer ( )
7
+ const bound = server . boundary ( fn )
8
+
9
+ bound ( { a : 1 } ) . toUpperCase ( )
10
+
11
+ bound ( {
12
+ // @ts -expect-error Expected number, got string.
13
+ a : '1' ,
14
+ } )
15
+
16
+ bound ( { a : 1 } )
17
+ // @ts -expect-error Unknown method ".fooBar()" on string.
18
+ . fooBar ( )
19
+
20
+ test (
21
+ 'should work' ,
22
+ server . boundary ( ( { expect } ) => {
23
+ expect ( true ) . toBe ( true )
24
+ // @ts -expect-error Property 'doesntExist' does not exist on type 'ExpectStatic'
25
+ expect . doesntExist
26
+ } ) ,
27
+ )
You can’t perform that action at this time.
0 commit comments