@@ -4,16 +4,21 @@ import {
44 createBehaviorStack ,
55} from './behaviors.ts'
66import { NotAMockFunctionError } from './errors.ts'
7- import type { AnyFunction , MockInstance } from './types.ts'
7+ import type {
8+ AnyCallable ,
9+ AnyFunction ,
10+ ExtractParameters ,
11+ MockInstance ,
12+ } from './types.ts'
813
914const BEHAVIORS_KEY = Symbol ( 'behaviors' )
1015
11- interface WhenStubImplementation < TFunc extends AnyFunction > {
12- ( ...args : Parameters < TFunc > ) : unknown
16+ interface WhenStubImplementation < TFunc extends AnyCallable > {
17+ ( ...args : ExtractParameters < TFunc > ) : unknown
1318 [ BEHAVIORS_KEY ] : BehaviorStack < TFunc >
1419}
1520
16- export const configureStub = < TFunc extends AnyFunction > (
21+ export const configureStub = < TFunc extends AnyCallable > (
1722 maybeSpy : unknown ,
1823) : BehaviorStack < TFunc > => {
1924 const spy = validateSpy < TFunc > ( maybeSpy )
@@ -26,10 +31,10 @@ export const configureStub = <TFunc extends AnyFunction>(
2631 const behaviors = createBehaviorStack < TFunc > ( )
2732 const fallbackImplementation = spy . getMockImplementation ( )
2833
29- const implementation = ( ...args : Parameters < TFunc > ) => {
34+ const implementation = ( ...args : ExtractParameters < TFunc > ) => {
3035 const behavior = behaviors . use ( args ) ?. behavior ?? {
3136 type : BehaviorType . DO ,
32- callback : fallbackImplementation ,
37+ callback : fallbackImplementation as AnyFunction | undefined ,
3338 }
3439
3540 switch ( behavior . type ) {
@@ -63,7 +68,7 @@ export const configureStub = <TFunc extends AnyFunction>(
6368 return behaviors
6469}
6570
66- export const validateSpy = < TFunc extends AnyFunction > (
71+ export const validateSpy = < TFunc extends AnyCallable > (
6772 maybeSpy : unknown ,
6873) : MockInstance < TFunc > => {
6974 if (
@@ -81,7 +86,7 @@ export const validateSpy = <TFunc extends AnyFunction>(
8186 throw new NotAMockFunctionError ( maybeSpy )
8287}
8388
84- export const getBehaviorStack = < TFunc extends AnyFunction > (
89+ export const getBehaviorStack = < TFunc extends AnyCallable > (
8590 spy : MockInstance < TFunc > ,
8691) : BehaviorStack < TFunc > | undefined => {
8792 const existingImplementation = spy . getMockImplementation ( ) as
0 commit comments