/** * Recursively makes all properties optional. * Arrays keep their element type (but each element is deeply partial). * Primitives and built-in value types (Date, RegExp) are preserved as-is. */ export type DeepPartial = T extends (infer U)[] ? DeepPartial[] : T extends Date | RegExp ? T : T extends object ? { [K in keyof T]?: DeepPartial } : T; /** * Re-types a function so its return value is wrapped in `Promise>`, * while keeping the original parameter types intact. * * Useful for typing Jest mock functions that return partial RPC/API data: * ```ts * const mock = jest.fn() as jest.MockedFunction>; * mock.mockResolvedValue({ onlyTheFieldsWeNeed: true }); * ``` */ export type DeepPartialReturn unknown> = ( ...args: Parameters ) => Promise>>>;