Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

188
Views
Do not allow extra properties with zod parse

I'm using zod for validation. It seems like if I define a schema and then parse() some input with some extra properties that aren't even in the schema, zod parses the input as valid but just removes those keys.

import { z } from 'zod'

const schema = z.object({
  foo: z.string(),
  bar: z.number()      
})

// this validates fine, printing { foo: 'hello', bar: 1 }
console.log(schema.parse({ foo: 'hello', bar: 1, baz: true })) 

However, extra input properties is not something I'd like to ignore, instead I'd like to throw a useful error when that happens, reporting the keys of the extra properties.

Is there a way to do that with zod?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use the strict option:

const schema = z.object({
  foo: z.string(),
  bar: z.number()      
}).strict();
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!