funtypes
funtypes copied to clipboard
Pick / Omit Object
It would be useful to have a way to get a copy of an object with only selected fields or with some fields excluded. See https://github.com/vriad/zod#pick-and-omit for inspiration.
Proposed API:
interface Record<T> {
pick<TKeys extends [keyof T, ...(keyof T)[]]>(...keys: TKeys): Record<Pick<T, TKeys[number]>>;
omit<TKeys extends [keyof T, ...(keyof T)[]]>(...keys: TKeys): Record<Omit<T, TKeys[number]>>;
}
Looks like I can pretty directly copy https://github.com/pelotom/runtypes/pull/161
Also requested in https://github.com/pelotom/runtypes/issues/148