@@ -141,6 +141,8 @@ export interface MockContext<T extends Procedure> {
141
141
}
142
142
143
143
type Procedure = ( ...args : any [ ] ) => any
144
+ // pick a single function type from function overloads, unions, etc...
145
+ type NormalizedPrecedure < T extends Procedure > = ( ...args : Parameters < T > ) => ReturnType < T >
144
146
145
147
type Methods < T > = keyof {
146
148
[ K in keyof T as T [ K ] extends Procedure ? K : never ] : T [ K ] ;
@@ -204,22 +206,22 @@ export interface MockInstance<T extends Procedure = Procedure> {
204
206
*
205
207
* If mock was created with `vi.spyOn`, it will return `undefined` unless a custom implementation was provided.
206
208
*/
207
- getMockImplementation ( ) : T | undefined
209
+ getMockImplementation ( ) : NormalizedPrecedure < T > | undefined
208
210
/**
209
211
* Accepts a function that will be used as an implementation of the mock.
210
212
* @example
211
213
* const increment = vi.fn().mockImplementation(count => count + 1);
212
214
* expect(increment(3)).toBe(4);
213
215
*/
214
- mockImplementation ( fn : T ) : this
216
+ mockImplementation ( fn : NormalizedPrecedure < T > ) : this
215
217
/**
216
218
* Accepts a function that will be used as a mock implementation during the next call. Can be chained so that multiple function calls produce different results.
217
219
* @example
218
220
* const fn = vi.fn(count => count).mockImplementationOnce(count => count + 1);
219
221
* expect(fn(3)).toBe(4);
220
222
* expect(fn(3)).toBe(3);
221
223
*/
222
- mockImplementationOnce ( fn : T ) : this
224
+ mockImplementationOnce ( fn : NormalizedPrecedure < T > ) : this
223
225
/**
224
226
* Overrides the original mock implementation temporarily while the callback is being executed.
225
227
* @example
@@ -231,7 +233,7 @@ export interface MockInstance<T extends Procedure = Procedure> {
231
233
*
232
234
* myMockFn() // 'original'
233
235
*/
234
- withImplementation < T2 > ( fn : T , cb : ( ) => T2 ) : T2 extends Promise < unknown > ? Promise < this> : this
236
+ withImplementation < T2 > ( fn : NormalizedPrecedure < T > , cb : ( ) => T2 ) : T2 extends Promise < unknown > ? Promise < this> : this
235
237
236
238
/**
237
239
* Use this if you need to return `this` context from the method without invoking actual implementation.
0 commit comments