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.

ts-to-zod support for auto generated zod object's strict()

See original GitHub issue

Feature description

Couldn’t find ts-to-zod way for enforcing strict on zod schema.

Input

export type Student = {
  name?:string;
};

Output

export const studentSchema = z.object({ name: z.string().optional() });

Expected Schema

export const studentSchema = z.object({
  name: z.string().optional()
}).strict();

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:4
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
eshita19commented, May 5, 2022

@fabien0102 Tried it. But it doesn’t work with nested type/interface. We would have to add strict() for all child types/interface.

0reactions
fabien0102commented, Dec 7, 2022

Sorry, I didn’t have the time recently… But I’m always open for PR reviews 😇

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issues · fabien0102/ts-to-zod - GitHub
Generate zod schemas from typescript types/interfaces - Issues · fabien0102/ts-to-zod. ... ts-to-zod support for auto generated zod object's strict().
Read more >
TypeScript-First Schema Validation with Static Type Inference
You can disallow unknown keys with .strict() . If there are any unknown keys in the input, Zod will throw an error. const...
Read more >
Zod | Documentation
Zod is a TypeScript-first schema declaration and validation library. I'm using the term "schema" to broadly refer to any data type, from a...
Read more >
Data validation with automatic typing using zod - CodeX Team
1. Validate without description a mountain of different if, instanceof, typeof and other things. 2. Have TypeScript types to represent the data we...
Read more >
Validating Input with Zod in TypeScript | by Dries Augustyns
Let's create a Zod schema to validate an entire object. ... Using strict() you can let Zod know that it should only allow...
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