/opt/canhelp/node_modules/zod/src/v4/classic/tests
NameSizeModeActions
anyunknown.test.ts6390644editdlrm
array.test.ts72840644editdlrm
assignability.test.ts67900644editdlrm
async-parsing.test.ts123110644editdlrm
async-refinements.test.ts18670644editdlrm
base.test.ts1790644editdlrm
bigint.test.ts19560644editdlrm
brand.test.ts22060644editdlrm
catch.test.ts72240644editdlrm
coalesce.test.ts7430644editdlrm
coerce.test.ts77360644editdlrm
continuability.test.ts74780644editdlrm
custom.test.ts12150644editdlrm
date.test.ts9620644editdlrm
datetime.test.ts115110644editdlrm
default.test.ts77170644editdlrm
description.test.ts12940644editdlrm
discriminated-unions.test.ts168100644editdlrm
enum.test.ts84880644editdlrm
error-utils.test.ts125720644editdlrm
error.test.ts195020644editdlrm
file.test.ts24600644editdlrm
firstparty.test.ts29770644editdlrm
function.test.ts62990644editdlrm
generics.test.ts21620644editdlrm
index.test.ts275620644editdlrm
instanceof.test.ts10520644editdlrm
intersection.test.ts47630644editdlrm
json.test.ts33090644editdlrm
lazy.test.ts47560644editdlrm
literal.test.ts24780644editdlrm
map.test.ts48170644editdlrm
nan.test.ts6450644editdlrm
nested-refine.test.ts36230644editdlrm
nonoptional.test.ts24050644editdlrm
nullable.test.ts5910644editdlrm
number.test.ts78270644editdlrm
object.test.ts159990644editdlrm
optional.test.ts41300644editdlrm
partial.test.ts48350644editdlrm
pickomit.test.ts44220644editdlrm
pipe.test.ts18480644editdlrm
prefault.test.ts10070644editdlrm
preprocess.test.ts69590644editdlrm
primitive.test.ts76490644editdlrm
promise.test.ts23150644editdlrm
prototypes.test.ts4980644editdlrm
readonly.test.ts117770644editdlrm
record.test.ts81180644editdlrm
recursive-types.test.ts73350644editdlrm
refine.test.ts147740644editdlrm
registries.test.ts59990644editdlrm
set.test.ts55720644editdlrm
standard-schema.test.ts13690644editdlrm
string-formats.test.ts30680644editdlrm
string.test.ts641240644editdlrm
stringbool.test.ts23330644editdlrm
template-literal.test.ts348360644editdlrm
to-json-schema.test.ts592760644editdlrm
transform.test.ts60000644editdlrm
tuple.test.ts47020644editdlrm
union.test.ts24970644editdlrm
validations.test.ts67360644editdlrm
void.test.ts3060644editdlrm
Edit: /opt/canhelp/node_modules/zod/src/v4/classic/tests/pickomit.test.ts (4422B)
import { expect, expectTypeOf, test } from "vitest"; import * as z from "zod/v4"; const fish = z.object({ name: z.string(), age: z.number(), nested: z.object({}), }); test("pick type inference", () => { const nameonlyFish = fish.pick({ name: true }); type nameonlyFish = z.infer; expectTypeOf().toEqualTypeOf<{ name: string }>(); }); test("pick parse - success", () => { const nameonlyFish = fish.pick({ name: true }); nameonlyFish.parse({ name: "bob" }); // @ts-expect-error checking runtime picks `name` only. const anotherNameonlyFish = fish.pick({ name: true, age: false }); anotherNameonlyFish.parse({ name: "bob" }); }); test("pick parse - fail", () => { fish.pick({ name: true }).parse({ name: "12" } as any); fish.pick({ name: true }).parse({ name: "bob", age: 12 } as any); fish.pick({ age: true }).parse({ age: 12 } as any); const nameonlyFish = fish.pick({ name: true }).strict(); const bad1 = () => nameonlyFish.parse({ name: 12 } as any); const bad2 = () => nameonlyFish.parse({ name: "bob", age: 12 } as any); const bad3 = () => nameonlyFish.parse({ age: 12 } as any); // @ts-expect-error checking runtime picks `name` only. const anotherNameonlyFish = fish.pick({ name: true, age: false }).strict(); const bad4 = () => anotherNameonlyFish.parse({ name: "bob", age: 12 } as any); expect(bad1).toThrow(); expect(bad2).toThrow(); expect(bad3).toThrow(); expect(bad4).toThrow(); }); test("pick - remove optional", () => { const schema = z.object({ a: z.string(), b: z.string().optional() }); expect("a" in schema._zod.def.shape).toEqual(true); expect("b" in schema._zod.def.shape!).toEqual(true); const picked = schema.pick({ a: true }); expect("a" in picked._zod.def.shape).toEqual(true); expect("b" in picked._zod.def.shape!).toEqual(false); }); test("omit type inference", () => { const nonameFish = fish.omit({ name: true }); type nonameFish = z.infer; expectTypeOf().toEqualTypeOf<{ age: number; nested: Record }>(); }); test("omit parse - success", () => { const nonameFish = fish.omit({ name: true }); nonameFish.parse({ age: 12, nested: {} }); // @ts-expect-error checking runtime omits `name` only. const anotherNonameFish = fish.omit({ name: true, age: false }); anotherNonameFish.parse({ age: 12, nested: {} }); }); test("omit parse - fail", () => { const nonameFish = fish.omit({ name: true }); const bad1 = () => nonameFish.parse({ name: 12 } as any); const bad2 = () => nonameFish.parse({ age: 12 } as any); const bad3 = () => nonameFish.parse({} as any); // @ts-expect-error checking runtime omits `name` only. const anotherNonameFish = fish.omit({ name: true, age: false }); const bad4 = () => anotherNonameFish.parse({ nested: {} } as any); expect(bad1).toThrow(); expect(bad2).toThrow(); expect(bad3).toThrow(); expect(bad4).toThrow(); }); test("omit - remove optional", () => { const schema = z.object({ a: z.string(), b: z.string().optional() }); expect("a" in schema._zod.def.shape).toEqual(true); const omitted = schema.omit({ a: true }); expect("a" in omitted._zod.def.shape).toEqual(false); }); test("nonstrict inference", () => { const laxfish = fish.pick({ name: true }).catchall(z.any()); type laxfish = z.infer; expectTypeOf().toEqualTypeOf<{ name: string; [k: string]: any }>(); }); test("nonstrict parsing - pass", () => { const laxfish = fish.passthrough().pick({ name: true }); laxfish.parse({ name: "asdf", whatever: "asdf" }); laxfish.parse({ name: "asdf", age: 12, nested: {} }); }); test("nonstrict parsing - fail", () => { const laxfish = fish.passthrough().pick({ name: true }); const bad = () => laxfish.parse({ whatever: "asdf" } as any); expect(bad).toThrow(); }); test("pick/omit/required/partial - do not allow unknown keys", () => { const schema = z.object({ name: z.string(), age: z.number(), }); expect(() => schema.pick({ name: true, asdf: true })).toThrow(); // @ts-expect-error expect(() => schema.pick({ $unknown: true })).toThrow(); // @ts-expect-error expect(() => schema.omit({ $unknown: true })).toThrow(); // @ts-expect-error expect(() => schema.required({ $unknown: true })).toThrow(); // @ts-expect-error expect(() => schema.partial({ $unknown: true })).toThrow(); });