Skip to content

About

Building Zod from zero to improve my expertise in TypeScript

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

17 Commits

Folders and files

Repository files navigation

TS Validation - Zod Clone

Building Zod from zero to improve my expertise in TypeScript

Completed

  • String (w/ only Optional & Nullable)
  • Boolean (w/ only Optional & Nullable)
  • Number (w/ only Optional & Nullable)
  • Object (w/ Optional & Nullable)
  • Nullable
  • Optional
  • Infer (String, Boolean, Number, Object, Optional, Nullable, Arrray)
  • Array

Todo

  • Parse
  • Min / Max / Length
  • Combine Optional / Nullable / Array

Example

/**
 * Définition du schéma de l'utilisateur
 */

const demoUserSchema = TSV.construct({
  ids: TSV.array(TSV.string())
  name: TSV.string(),
  age: TSV.nullable(TSV.number()),
  isSubscribed: TSV.optional(TSV.boolean()),
  address: TSV.construct({
    street: TSV.string(),
    city: TSV.string(),
    country: TSV.string(),
  }).optional(),
});

/**
 * Récupération du type de l'utilisateur depuis le schéma
 */

type DemoUser = TSV.Infer<typeof demoUserSchema>;

/**
 * Format du type infer depuis le schéma
 *
 * type DemoUser = {
 *  ids: string[]
 *  name: string;
 *  age: number | null;
 *  isSubscribed?: boolean | undefined;
 *  address?: {
 *   street: string;
 *   city: string;
 *   country: string;
 *  } | undefined;
 * }
 *
 */

Inspired by

About

Building Zod from zero to improve my expertise in TypeScript

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages