I'm trying to preset a property of an object which is passed as an argument to a function. This way i don't have to set this specific property as it is already provided when i call this function later.
The use case is to set the version for api calls.
withApiVersion
const API_VERSION = "1";
const addApiVersion = <T>(obj: T) => ({ ...obj, version: API_VERSION });
export const withApiVersion = <Fn extends (arg: any) => any>(fn: Fn) => <Arg>(
arg: Arg
): ReturnType<Fn> => fn(addApiVersion(arg));
Example api method
export const getCertificates = ({
version,
searchString,
skip,
take = 50
}: {
version: string;
searchString?: string;
skip?: number;
take?: number;
}) => Promise.resolve([{ id: 1 }]);
const result = withApiVersion(getCertificates);
Everything works fine except that i can't get the correct type after the "partial application" of the function's argument -> ideally withApiVersion will return a function which expects an argument where the version property is missing.
Thx in advance for any help or tipp!