Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

305
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda