/* eslint-disable @typescript-eslint/no-unused-vars */ /* eslint-disable @typescript-eslint/no-explicit-any */ type IfAny = 0 extends 1 & T ? Y : N; type IsAny = IfAny; type TypeWithGeneric = T[]; // eslint-disable-next-line @typescript-eslint/no-explicit-any // type extractGeneric = // Type extends jest.MaybeMockedDeep ? X : never; // eslint-disable-next-line @typescript-eslint/no-explicit-any type JestMockAny = jest.Mock; // eslint-disable-next-line @typescript-eslint/no-explicit-any type JestMockString = jest.Mock; type IsJestMockAny = IsAny< ReturnType, never, jest.MaybeMockedDeep >; const fn = jest.fn(); const result = fn(1, 2, 3); type A = IsJestMockAny; type B = IsJestMockAny; const b: B = (a, b) => {}; export type MockedService< T extends Record > = { // https://stackoverflow.com/questions/78674994/is-there-way-to-say-but-doesnt-match-any-in-typescript/78675024#78675024 [K in keyof T]: IsJestMockAny; } & T; type Foo = { getA: (a: string, b: string) => Promise<{ c: string }>; getB: (e: number, f: number) => Promise<{ g: string }>; }; const mockedFoo: MockedService = { getA: jest.fn().mockRejectedValue(new Error('not implemented')), // nb. The mock return values are not stricted enforced, if you // don't wrap with jest.mocked! getB: jest.fn() }; function createMockedService< T extends Record, V extends MockedService >(value: V) { return value; } createMockedService({ getA: jest.fn().mockRejectedValue(new Error('not implemented')), // nb. The mock return values are not stricted enforced, if you // don't wrap with jest.mocked! getB: jest.fn() }); mockedFoo.getB(1, 2);