Docs / Validation and contracts
is()Supported
A compile-time type guard: is<T>(value) returns boolean and narrows the input on success. With the AOT transform it inlines to the exact structural checks T implies — no runtime schema, no reflection.
Usage#
import { is } from '@zmdb/validator';
if (is<CreateUser>(payload)) {
// payload is narrowed to CreateUser here
await users.create(payload);
}What the transform emits#
For a type like { email: string; age: number }, the call site compiles to a straight-line boolean expression:
// authored
is<{ email: string; age: number }>(d)(
// compiled (AOT)
typeof d === 'object' && d !== null && typeof d.email === 'string' && typeof d.age === 'number',
);📝 Note
This is the same single boolean-chain shape typia emits — and in our benchmarks it out-performs new Function() JIT validators. Without the transform wired in, is falls back to a slower runtime walk of the type descriptor.
Related#
- assert() — throw with the failing path
- validate() — collect every error
- Special tags — constraints like
Min/Pattern