pick

Creates a modified copy of an object schema that contains only the selected entries.

const Schema = pick<TSchema, TKeys>(schema, keys);

Generics

Parameters

  • schema TSchema
  • keys TKey

Explanation

pick creates modified copy of the given object schema that containing only the selected keys. It is similar to TypeScript's Pick utility type.

Because pick changes the data type of the input and output, it is not allowed to pass a schema that has been modified by the pipe method, as this may cause runtime errors. Please use the pipe method after you have modified the schema with pick.

Returns

  • Schema SchemaWithPick<TSchema, TKeys>

Examples

The following examples show how pick can be used.

Pick specific keys

Schema that contains only the selected keys of an existing schema.

const PickedSchema = pick(
  object({
    key1: string(),
    key2: number(),
    key3: boolean(),
  }),
  ['key1', 'key3']
); // { key1: string; key3: boolean }

The following APIs can be combined with pick.

Schemas

Methods

Actions

Contributors

Thanks to all the contributors who helped make this page better!

  • GitHub profile picture of fabian-hiller

Partners

Thanks to our partners who support the project ideally and financially.

Sponsors

Thanks to our GitHub sponsors who support the project financially.

  • GitHub profile picture of dailydotdev
  • GitHub profile picture of KATT
  • GitHub profile picture of osdiab
  • GitHub profile picture of Thanaen
  • GitHub profile picture of ruiaraujo012
  • GitHub profile picture of hyunbinseo
  • GitHub profile picture of caegdeveloper
  • GitHub profile picture of seahindeniz