question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature request: `.deepStrict`

See original GitHub issue

Like .deepPartial is to .partial it would be beneficial to have a .deepStrict function that ensures every level in an object, array, or tuple hierarchy is .strict.

For example, this code does not generate a ZodError:

const person = z
  .object({
    name: z.string(),
    meta: z.object({
      born: z.string(),
    }),
  })
  .strict();

person.parse({
  name: "bob dylan",
  meta: {
    born: "a place",
    extraKey: 61,
  },
});

With .deepStrict it would work like this:

const person = z
  .object({
    name: z.string(),
    meta: z.object({
      born: z.string(),
    }),
  })
  .deepStrict();

person.parse({
  name: "bob dylan",
  meta: {
    born: "a place",
    extraKey: 61,
  },
});
// => throws ZodError

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:2
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
renatoarghcommented, Sep 30, 2022

When using Joi there is kind of a “global” option you can enable so that the strict feature will be applied recursively across all your objects by default. For sure it is a challenge to make such configuration reflect statically in the types but maybe it is a really good improvement to Zod to introduce such feature in runtime only at least.

Not sure about the implementation details but from the developer perspective it would be something like this:

schema.safeParse({
  deepStrict: true,
})
1reaction
colinhackscommented, Sep 6, 2022

This is very hard to do in the static domain. Currently .deepPartial is very limited and error-prone for similar reasons. I’ll leave this open but I recommend using z.strictObject if you want a shorthand for declaring lots of strict objects without needing a method.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Feature request tracking: 3 strategies to do it better
Feature requests scattered across channels? Use these 3 PROVEN strategies for tracking and managing feature requests effortlessly.
Read more >
How To Manage Feature Requests [Template included]
This guide will teach you everything about feature requests – how to process them, manage them, respond to them, prioritize them – so...
Read more >
Feature Requests: How to Track, Prioritize, and Manage - Pipefy
Feature requests are demands for improvement in a company's product. Click to learn how to track and prioritize these requests efficiently!
Read more >
Feature request: `.deepStrict` - PullAnswer
Feature request : `.deepStrict` ... deepStrict function that ensures every level in an object, array, or tuple hierarchy is .strict .
Read more >
Feature requests that don't suck - Medium
TLDR Feature requests normally suck but can be powerful if done right. Get a feature request template that works here. Feature requests are ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found