Skip to content

Commit 6feba21

Browse files
authored
refactor(types)!: revert #23 due to Vitest revert (#37)
1 parent 9e8e0da commit 6feba21

File tree

5 files changed

+23
-13
lines changed

5 files changed

+23
-13
lines changed

eslint.config.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,17 @@ export default defineConfig(
1414
'unicorn/no-array-reverse': 'off',
1515
},
1616
},
17+
{
18+
files: ['src/types.ts'],
19+
rules: {
20+
'@typescript-eslint/no-explicit-any': 'off',
21+
},
22+
},
23+
{
24+
files: ['test/typing.test-d.ts'],
25+
rules: {
26+
'@typescript-eslint/no-unsafe-argument': 'off',
27+
},
28+
},
1729
globalIgnores(['**/coverage/**', '**/dist/**']),
1830
)

src/types.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
/* eslint-disable @typescript-eslint/no-explicit-any */
21
/** Common type definitions. */
3-
import type { AsymmetricMatcher } from '@vitest/expect'
42
import type { MockedClass, MockedFunction } from 'vitest'
53

64
/** Any function. */
@@ -81,11 +79,6 @@ export type ConstructorImplementation<
8179
| (new (...args: ConstructorParameters<TFunc>) => InstanceType<TFunc>)
8280
| ((this: InstanceType<TFunc>, ...args: ConstructorParameters<TFunc>) => void)
8381

84-
/** Accept a value or an AsymmetricMatcher in an arguments array */
85-
export type WithMatchers<T extends unknown[]> = {
86-
[K in keyof T]: AsymmetricMatcher<unknown> | T[K]
87-
}
88-
8982
/** A mocked function or constructor. */
9083
export type Mock<TFunc extends AnyMockable> = TFunc extends AnyConstructor
9184
? MockedClass<TFunc>

src/vitest-when.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import type {
1010
NormalizeMockable,
1111
ParametersOf,
1212
ReturnTypeOf,
13-
WithMatchers,
1413
} from './types.ts'
1514

1615
export { type Behavior, BehaviorType, type WhenOptions } from './behaviors.ts'
@@ -21,9 +20,7 @@ export interface StubWrapper<
2120
TFunc extends AnyMockable,
2221
TOptions extends WhenOptions | undefined,
2322
> {
24-
calledWith<TArgs extends ArgumentsSpec<ParametersOf<TFunc>, TOptions>>(
25-
...args: WithMatchers<TArgs>
26-
): Stub<TFunc>
23+
calledWith(...args: ArgumentsSpec<ParametersOf<TFunc>, TOptions>): Stub<TFunc>
2724
}
2825

2926
export interface Stub<TFunc extends AnyMockable> {

test/typing.test-d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ describe('vitest-when type signatures', () => {
7575
subject
7676
.when(multipleArgs, { ignoreExtraArgs: true })
7777
.calledWith(expect.any(Number), expect.any(String), expect.any(Boolean))
78+
79+
subject.when(multipleArgs, { ignoreExtraArgs: true }).calledWith(
80+
// @ts-expect-error: too many arguments
81+
expect.anything(),
82+
expect.anything(),
83+
expect.anything(),
84+
expect.anything(),
85+
)
7886
})
7987

8088
it('returns mock type for then resolve', () => {

test/vitest-when.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ describe('vitest-when', () => {
281281
})
282282

283283
it.each([
284-
{ stubArgs: [] as unknown[], callArgs: [] as unknown[] },
284+
{ stubArgs: [], callArgs: [] },
285285
{ stubArgs: [], callArgs: ['a'] },
286286
{ stubArgs: [], callArgs: ['a', 'b'] },
287287
{ stubArgs: ['a'], callArgs: ['a'] },
@@ -300,7 +300,7 @@ describe('vitest-when', () => {
300300
)
301301

302302
it.each([
303-
{ stubArgs: ['a'] as unknown[], callArgs: ['b'] as unknown[] },
303+
{ stubArgs: ['a'], callArgs: ['b'] },
304304
{ stubArgs: [undefined], callArgs: [] },
305305
])(
306306
'does not match call $callArgs against stub $stubArgs with ignoreExtraArgs',

0 commit comments

Comments
 (0)