ForbesLindesay / funtypes

Runtime validation for static types
MIT License
29 stars 4 forks source link

Pick / Omit Object #13

Open ForbesLindesay opened 4 years ago

ForbesLindesay commented 4 years ago

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 commented 3 years ago

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

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