funtypes icon indicating copy to clipboard operation
funtypes copied to clipboard

Pick / Omit Object

Open ForbesLindesay opened this issue 5 years ago • 1 comments

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]>>;
}

ForbesLindesay avatar Sep 06 '20 15:09 ForbesLindesay

Looks like I can pretty directly copy https://github.com/pelotom/runtypes/pull/161

Also requested in https://github.com/pelotom/runtypes/issues/148

ForbesLindesay avatar Sep 11 '20 02:09 ForbesLindesay