Jessevanassen
I tried that with the example above, but when you pass in an empty function, the parameters will be inferred as `[]`, regardless if you initialize `TArgs` with `any[]` or `any` in the type definitions (or leave it out completely, [which is what `@types/jest` is doing](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/af319cfd1b58be68166cfb117bed37f1e4d45baa/types/jest/index.d.ts#L254)).
This behavior is actually consistent between Vitest and Jest.
**vitest.test.ts** (with `TArgs` set to `any`):
```ts
import { vi, type Mocked } from 'vitest';
type Subject = {
doSomething(x: string): boolean;
};
const mockedSubject: Mocked<Subject> = {
doSomething: vi.fn().mockReturnValue(true),
};
const mockedSubjectWithoutArgs: Mocked<Subject> = {
doSomething: vi.fn(() => true),
};
/*
src/vitest.test.ts:12:2 - error TS2322: Type 'Mock<[], boolean>' is not assignable to type 'MockInstance<[x: string], boolean> & ((x: string) => boolean)'.
Type 'Mock<[], boolean>' is not assignable to type 'MockInstance<[x: string], boolean>'.
The types of 'mockName(...).mock' are incompatible between these types.
Type 'MockContext<[], boolean>' is not assignable to type 'MockContext<[x: string], boolean>'.
Type '[]' is not assignable to type '[x: string]'.
Source has 0 element(s) but target requires 1.
12 doSomething: vi.fn(() => true),
~~~~~~~~~~~
src/vitest.test.ts:4:2
4 doSomething(x: string): boolean;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The expected type comes from property 'doSomething' which is declared here on type 'Mocked<Subject>'
*/
const mockedSubjectWithCorrectArgs: Mocked<Subject> = {
doSomething: vi.fn((x) => true),
};
const mockedSubjectWithTooManyArgs: Mocked<Subject> = {
doSomething: vi.fn((x, y) => true),
};
/*
src/vitest.test.ts:20:2 - error TS2322: Type 'Mock<[x: string, y: TArgs[1]], boolean>' is not assignable to type 'MockInstance<[x: string], boolean> & ((x: string) => boolean)'.
Type 'Mock<[x: string, y: TArgs[1]], boolean>' is not assignable to type 'MockInstance<[x: string], boolean>'.
The types of 'mockName(...).mock' are incompatible between these types.
Type 'MockContext<[x: string, y: TArgs[1]], boolean>' is not assignable to type 'MockContext<[x: string], boolean>'.
Type '[x: string, y: TArgs[1]]' is not assignable to type '[x: string]'.
Source has 2 element(s) but target allows only 1.
20 doSomething: vi.fn((x, y) => true),
~~~~~~~~~~~
src/vitest.test.ts:4:2
4 doSomething(x: string): boolean;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The expected type comes from property 'doSomething' which is declared here on type 'Mocked<Subject>'
*/
```
**jest.test.ts**:
```ts
type Subject = {
doSomething(x: string): boolean;
};
const mockedSubject: jest.Mocked<Subject> = {
doSomething: jest.fn().mockReturnValue(true),
};
const mockedSubjectWithoutArgs: jest.Mocked<Subject> = {
doSomething: jest.fn(() => true),
};
/*
src/jest.test.ts:10:2 - error TS2322: Type 'Mock<boolean, [], unknown>' is not assignable to type 'MockInstance<boolean, [x: string], unknown> & ((x: string) => boolean)'.
Type 'Mock<boolean, [], unknown>' is not assignable to type 'MockInstance<boolean, [x: string], unknown>'.
Types of property 'mock' are incompatible.
Type 'MockContext<boolean, [], unknown>' is not assignable to type 'MockContext<boolean, [x: string], unknown>'.
Type '[]' is not assignable to type '[x: string]'.
Source has 0 element(s) but target requires 1.
10 doSomething: jest.fn(() => true),
~~~~~~~~~~~
src/jest.test.ts:2:2
2 doSomething(x: string): boolean;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The expected type comes from property 'doSomething' which is declared here on type 'Mocked<Subject>'
*/
const mockedSubjectWithCorrectArgs: jest.Mocked<Subject> = {
doSomething: jest.fn((x) => true),
};
const mockedSubjectWithTooManyArgs: jest.Mocked<Subject> = {
doSomething: jest.fn((x, y) => true),
};
/*
src/jest.test.ts:18:2 - error TS2322: Type 'Mock<boolean, [x: string, y: Y[1]], unknown>' is not assignable to type 'MockInstance<boolean, [x: string], unknown> & ((x: string) => boolean)'.
Type 'Mock<boolean, [x: string, y: Y[1]], unknown>' is not assignable to type 'MockInstance<boolean, [x: string], unknown>'.
Types of property 'mock' are incompatible.
Type 'MockContext<boolean, [x: string, y: Y[1]], unknown>' is not assignable to type 'MockContext<boolean, [x: string], unknown>'.
Type '[x: string, y: Y[1]]' is not assignable to type '[x: string]'.
Source has 2 element(s) but target allows only 1.
18 doSomething: jest.fn((x, y) => true),
~~~~~~~~~~~
src/jest.test.ts:2:2
2 doSomething(x: string): boolean;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The expected type comes from property 'doSomething' which is declared here on type 'Mocked<Subject>'
*/
```
On 07 Mar 2023 at 05:58:29