/home/techb158/balavpn.abdallabala.com/node_modules/zod/src/v4/mini/tests
NameSizeModeActions
assignability.test.ts33010666editdlrm
brand.test.ts18410666editdlrm
checks.test.ts40710666editdlrm
computed.test.ts11680666editdlrm
error.test.ts6440666editdlrm
functions.test.ts11760666editdlrm
index.test.ts287530666editdlrm
number.test.ts36650666editdlrm
object.test.ts51900666editdlrm
prototypes.test.ts8700666editdlrm
recursive-types.test.ts56400666editdlrm
string.test.ts112230666editdlrm
Edit: /home/techb158/balavpn.abdallabala.com/node_modules/zod/src/v4/mini/tests/brand.test.ts (1841B)
import { expectTypeOf, test } from "vitest"; import * as z from "../index.js"; test("branded types", () => { const mySchema = z .object({ name: z.string(), }) .brand<"superschema">(); // simple branding type MySchema = z.infer; // Using true for type equality assertion expectTypeOf().toEqualTypeOf<{ name: string } & z.$brand<"superschema">>(); const doStuff = (arg: MySchema) => arg; doStuff(z.parse(mySchema, { name: "hello there" })); // inheritance const extendedSchema = mySchema.brand<"subschema">(); type ExtendedSchema = z.infer; expectTypeOf().toEqualTypeOf<{ name: string } & z.$brand<"superschema"> & z.$brand<"subschema">>(); doStuff(z.parse(extendedSchema, { name: "hello again" })); // number branding const numberSchema = z.number().brand<42>(); type NumberSchema = z.infer; expectTypeOf().toEqualTypeOf(); // symbol branding const MyBrand: unique symbol = Symbol("hello"); type MyBrand = typeof MyBrand; const symbolBrand = z.number().brand<"sup">().brand(); type SymbolBrand = z.infer; // number & { [z.$brand]: { sup: true, [MyBrand]: true } } expectTypeOf().toEqualTypeOf & z.$brand>(); // keeping brands out of input types const age = z.number().brand<"age">(); type Age1 = z.infer; type AgeInput1 = z.input; // Using not for type inequality assertion expectTypeOf().not.toEqualTypeOf(); expectTypeOf().toEqualTypeOf(); expectTypeOf>().toEqualTypeOf(); // @ts-expect-error doStuff({ name: "hello there!" }); });