Skip to content

Add support for more extended validation instead of just looking at the data type #29

@Rednas83

Description

@Rednas83

Something like

// source.ts
export interface HeroContact {
  email: string; // v-email
  name: string; // 2..50
  phoneNumber: string; // p-^([+]?d{1,2}[-s]?|)d{3}[-s]?d{3}[-s]?d{4}$
  hasSuperPower?: boolean; // v-true
  age: number; // 0..500
}

// output.ts
export const heroContactSchema = z.object({
  email: z.string().email(),
  name: z.string().min(2).max(50),
  phoneNumber: z.string().regex(/^([+]?d{1,2}[-s]?|)d{3}[-s]?d{3}[-s]?d{4}$/),
  hasSuperPower: z.boolean().default(true),
  age: z.number().min(0).max(500),
});

Whereby v- is a shorthand for validation and p- is a shorthand for pattern

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions