
ALT // Zod import { z } from "zod"; const userSchema = z.object({ name: z.string(), age: z.number(), }); type User = z.infer<typeof userSchema>; // Infer the type from the schema // This throws if the object passed doesn't match the schema const user = userSchema.parse({ name: "John Doe", age: 42, });

ALT // Arktype (Zod alternative) import { type } from "arktype"; const userType = type({ username: "string", email: "string.email", }); type User = typeof userType.infer; // Infer the type from the schema const result = userType({ name: "John Doe", age: 42, }); if (result instanceof type.errors) { console.log(result.summary); } else { // result is now of type User console.log(result); console.log("success"); }






















