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

294
Views
How not to allow unknown properties after zod transform method (TypeScript)

I have an API function that returns a user, for example. I want to parse response from the server to my client User type. Let's say e.g. I want to merge first and last name of a user into one string to use in my client code.


type User = {
    uuid: string
    email: string
    fullName: string
}

const UserSchema: z.ZodSchema<User, z.ZodTypeDef, unknown> = z.object({
    uuid: z.string().uuid(),
    email: z.string().email(),
    firstName: z.string(),
    lastName: z.string()
}).transform(response => ({
    uuid: response.uuid,
    email: response.email,
    fullName: `${response.firstName} ${response.lastName}`
}))

and that works perfectly fine from TypeScript perspective. E.g. if I try to set non string value to fullName inside transform it shows an error. BUT it allows me to add properties to the final result without showing any errors:

...}).transform(response => ({
    uuid: response.uuid,
    email: response.email,
    fullName: `${response.firstName} ${response.lastName}`,
    
    // here is an extra value that should not be here because it
    // doesn't exist in my client User type but TS allows it here
    blablabla: true,
}))

I have strict and strictNullChecks enabled in my tsconfig file. How can I make an error visible in such cases?

about 4 years ago · Juan Pablo Isaza
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!