Skip to content

Commit c130e19

Browse files
committed
Improve typing
1 parent 5054078 commit c130e19

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/types.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,11 @@ export type Mock<TFunc extends AnyMockable> = TFunc extends AnyConstructor
8282
: TFunc extends AnyFunction
8383
? MockedFunction<TFunc>
8484
: never
85+
86+
/** Produce a union of progressively longer tuples based on the input tuple */
87+
export type PartialArguments<
88+
Tuple extends any[],
89+
_Previous extends any[] = [],
90+
> = Tuple extends [infer First, ...infer Rest]
91+
? [..._Previous, First] | PartialArguments<Rest, [..._Previous, First]>
92+
: never

src/vitest-when.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import type {
88
MockInstance,
99
NormalizeMockable,
1010
ParametersOf,
11+
PartialArguments,
1112
ReturnTypeOf,
1213
WithMatchers,
1314
} from './types.ts'
@@ -24,7 +25,7 @@ export interface StubWrapper<TFunc extends AnyMockable> {
2425

2526
export interface StubWrapperFlexible<TFunc extends AnyMockable> {
2627
calledWith<TArgs extends ParametersOf<TFunc>>(
27-
...args: Partial<WithMatchers<TArgs>>
28+
...args: PartialArguments<WithMatchers<TArgs>>
2829
): Stub<TFunc>
2930
}
3031

0 commit comments

Comments
 (0)