arktypea
arktype10mo ago
thibault

How to set an error message

Hey guys, I am trying to move this zod schema with arktype:

const userZodSchema = z.object({
  name: z
    .string({
      required_error: "name is required",
      invalid_type_error: "name must of type string",
    })
    .trim()
    .min(3, "name must be at least 3 characters")
    .max(255, "name must be at most 255 characters"),
});


so far I have come up with this, but how would I set the error message ?:
const userArktypeSchema = type({
  name: '0<string.trim.preformatted<255'
});


here is a typescript playground:

https://www.typescriptlang.org/play/?ssl=15&ssc=1&pln=19&pc=1#code/JYWwDg9gTgLgBAbxgTzAUwL5wGZQiOAcgEMoBrFdQgbgChRJZEAvLXfI5iAExttoDGEAHYBneAFdRaKAC0eAZQEALNCGJwAvHGYA6CACMAVmgEwAFAlpw4w4iDQAuHdZtxd4qMGEBzS67c4KDQARwlgYO4AfRk8KGcAIjsHOGBRINDwyISAGgC3bwA3YgAbYGjKNBioOMTktDgQKXgIbDhKuE9vH1z8jABKfN0YLxBzQcDdEG9zAGYcuCT7BqbxOAMG4ngStGI12bgVUmIzGVEEibcp4gAPcwAmAFZHhaWU1fgNuC3GiDWnx6HZTHU5Qc79PIDOiCERrKQyACC5EqSlU6i07VQaH8NnqzkIAAYADxdXzDUa6MDBbDQdQwGBobhEgGEWgDfgcoA
The Playground lets you write TypeScript or JavaScript online in a safe and sharable way.
Was this page helpful?