turkerdev / fastify-type-provider-zod

MIT License
386 stars 24 forks source link

Can't find regex on z.string #81

Open netgfx opened 4 months ago

netgfx commented 4 months ago

I get Property 'regex' does not exist on type 'ZodEffects<ZodString, string, string>'

I define the z.strng like this:

z.string({
        required_error: 'Username is required',
        invalid_type_error: 'Name must be a string',
      })
      .refine(
        (data: string) => data.length > 0,
        (val: string) => ({
          message: 'Username cannot be empty',
        }),
      )
      .regex(/^[a-zA-Z0-9]+$/, {
        message: 'Username can only contain alphanumeric characters',
      })
      .min(3, {message: 'Username must be at least 3 characters long'})
      .max(20, {message: 'Username cannot exceed 20 characters'})

Could this be because the zod version of the library is outdated? Locally I have zod version 3.23.8

kibertoad commented 4 months ago

might be. I'll try to release the updated version this week

kibertoad commented 4 months ago

Can you please try 1.2.0?