May 12, 2024, 9:16 a.m. | YPChen

DEV Community

Valibot's playground for the code demo

Recursive Type in TypeScript

TypeScript allows defining recursive types. For example, consider the following User interface:

interface User {
children?: User;
email: `${string}@${string}`;
password: string;

Using Valibot for Schema Validation

What if you use a schema library, like Zod or Valibot? The schema has been built on value-level, and you cannot assign the variant to its property inside the declaration.

import * as v from 'valibot';

const EmailSchema = v.string([v.minLength(1),]);
const …

children code demo email interface library password types typescript user interface valibot validation

Sr. Product Manager

@ MixMode | Remote, US

Information Security Engineers

@ D. E. Shaw Research | New York City

Technology Security Analyst

@ Halton Region | Oakville, Ontario, Canada

Senior Cyber Security Analyst

@ Valley Water | San Jose, CA

Security Operations Analyst, Senior

@ Booz Allen Hamilton | USA, WV, Clarksburg (1000 Custer Hollow Rd)

Security Solution Consultant

@ Genesys | Durham (Flexible)