new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Zod · all subjects

schema definitions/literals

7 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Literal schemas for exact values

Use z.literal() to create a schema that only accepts a specific literal value. Examples: z.literal('tuna'), z.literal(12), z.literal(2n), z.literal(true). To represent JavaScript literals null and undefined, use z.null() and z.undefined() (or z.void() as an alias). To allow multiple literal values, pass an array: z.literal(['red', 'green', 'blue']).

Extract values from z.literal() using .values

For a literal schema that accepts multiple values, use .values to extract the set of allowed values as a Set. For example: z.literal(['red', 'green', 'blue']).values returns Set<'red' | 'green' | 'blue'>. This is available in Zod but not Zod Mini.

z.enum() for string enumerations

z.enum() validates inputs against a fixed set of allowable string values. Pass an array directly to z.enum() or use 'as const' assertion. Example: z.enum(['Salmon', 'Tuna', 'Trout']). Supports enum-like object literals: z.enum({ Salmon: 0, Tuna: 1 }). Supports TypeScript enums: z.enum(EnumName).

Extract enum values from z.enum()

For a z.enum() schema, access .enum property to get an enum-like object. Example: z.enum(['Salmon', 'Tuna', 'Trout']).enum returns { Salmon: 'Salmon', Tuna: 'Tuna', Trout: 'Trout' }. In Zod Mini, use .def.entries instead.

z.enum().exclude() and .extract() methods

z.enum().exclude(values) creates a new enum schema excluding specified values. z.enum().extract(values) creates a new enum schema extracting only specified values. These are available in Zod but not Zod Mini.

z.enum() requires array literal or as const assertion

When declaring a string array as a variable without 'as const', Zod cannot infer the exact values and will infer string type. Always pass the array directly into z.enum() or use 'as const' assertion on the array variable.

z.literal() accepts multiple values

z.literal([200, 201, 202, 204, 206, 207, 208, 226]) accepts an array of values, replacing the need for z.union([z.literal(200), z.literal(201), ...]).

Give your agent this brain