Skip to main content

is.object({ ... })

Validates that a value is a plain object whose fields satisfy the provided shape. Fields not listed in the shape are allowed by default.

Helpers

.strict (Transformer Property) — disallows extra keys not listed in the shape.
.partial() (Transformer Factory) — makes all fields optional (T | undefined). If an array of keys is passed as argument, only those keys become optional.
.required() (Transformer Factory) — makes all fields required. If an array of keys is passed as argument, only those keys become required.
.pick([keys]) (Transformer Factory) — keeps only the listed keys.
.omit([keys]) (Transformer Factory) — removes the listed keys from the shape.
.extend({ ... }) (Transformer Factory) — merges additional fields into the shape. Returns a new guard. Prefer this over the top-level is.and() for merging objects.
.catchall(innerGuard) (Transformer Factory) — allows any extra keys not defined in the schema, but only if they satisfy the provided guard.

Other object helpers


is.array(guard?)

Validates that a value is an array. Pass one or more element guards to validate every item.

Helpers


is.record(keyGuard, valueGuard)

Validates that a value is a plain object where every key and value satisfies the provided guards. When keyGuard has a finite set of values (is.enum or is.literal), the record performs exhaustive key checking — all keys must be present and no extra keys are allowed. This matches TypeScript’s Record<'a' | 'b', V> semantics. When keyGuard is open-ended (is.string, is.number), it validates that every existing key/value pair satisfies the guards without requiring any specific keys.
is.record has all of the same helpers as is.object

is.tuple([...], restGuard?)

Validates a fixed-length array where each position has its own guard. Pass a second argument to allow variadic trailing elements.

is.union(...), is.intersection(...), is.xor(...)

is.union(...guards) — passes if the value satisfies at least one guard.
is.intersection(...guards) — passes if the value satisfies all guards.
is.xor(...guards) — passes if the value satisfies exactly one guard.

Built-in type guards

is.date

Validates a Date instance.

is.regexp

Validates a RegExp instance. Optionally validates against a specific pattern.

is.url

Validates a URL instance (not a string — use is.string.url for strings).

is.map(keyGuard?, valueGuard?)

Validates a Map instance with optional key and value guards.

is.set(valueGuard?)

Validates a Set instance with an optional value guard.

is.promise

Validates any thenable (has a .then method). There are very few use-cases for this.

is.error

Validates an Error instance.

is.file

Validates a File or Blob instance.

Custom and chas-specific guards

is.custom(fn)

Creates a guard from any predicate function. Use a TypeScript type predicate for full narrowing, or pass a generic type parameter.

is.result()

Guards a Result<T, E> value from the ts-chas result module.

is.option()

Guards an Option<T> value.

is.tagged(factory)

Guards tagged errors created with defineErrs.