I would like to create a function that takes some partial props to populate a type, and returns another function, which in turn accepts exactly the remainging props to create an object of the type.
declare function creator<T extends U>(defaults: U) =>
(fields: Pick<T, Exclude<keyof U, keyof T>>) => T
so that I can do:
type A = { a: number, b: string };
const make = creator<A>({ a: 1 }); // ({ b: string }) => A
- I don't know how to let
creatoronly acceptTat call-time, but declare it extendingUand inferU. - I don't know why I cannot "construct"
TfromUandPick<T, Exclude<keyof U, keyof T>>with generics. It is possible with types directly:
type T = { a: number; b: string };
type A = { a: number };
type T1 = A & Pick<T, Exclude<keyof A, keyof T>>;
const t1: T = { a: 1, b: "b" };
const t2: T1 = t1;