Skip to content

Is there a way to deepPick, similar to deepPartial? #2072

@DoubleDebug

Description

@DoubleDebug

Problem

I want to pick deeply nested properties.
In the example below, I want to get the validation schema for the school name property, which is 2 levels deep from the initial "person" object. Using the method pick, I can extract properties that are 1 level deep and I can get the "school" object. However, I cannot go deeper and get the properties of the school object. Is there another way to achieve this?

Schema:

const person = z.object({
  name: z.string(),
  school: z.object({
    id: z.number(),
    name: z.string()
  })
});

Desired solution

const justSchoolName = person.deepPick({
  school: {
    name: true
  }
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions