API reference › @evolu/common › Type
Runtime validation with precise TypeScript types and structured errors.
Evolu Type is a pure, synchronous codec for defining semantic domains.
It partially decodes an Input into an Output and totally encodes every
valid Output into a CanonicalInput. Types can validate, refine,
transform, and compose without losing the contracts TypeScript can express.
Decoding failures are explicit Result values, and their structured errors preserve the exact error types each Type can return.
Evolu Type is designed to make correct code the easiest code to write:
- Predefined constraints add a Brand to their Output.
- Invalid declarations produce readable CompileTimeError types when the compiler can detect them.
- Evolu Type uses runtime assertions to detect developer errors that TypeScript cannot express, such as excess properties and sparse arrays.
- Typed
fromboundaries allow connecting value producers to domain fields through their exact TypeScript types, so incompatible contract changes are compile-time errors rather than runtime validation errors. - Lawful codecs compose without creating unencodable values: every valid Output has a canonical Input representation and round-trips to the same semantic value.
- Type-safe localization infers the required error formatters from selected Types, so missing validation messages are compile-time errors.
Correctness is especially important for local-first data: application authors cannot inspect or repair a user's data.
Evolu Type is optimized for small real-world bundles: composed Types share runtime code, while unused validators and formatters are tree-shaken. It could be smaller with less descriptive assertion messages, but Evolu favors actionable diagnostics over micro-optimizing isolated Types.
Predefined Types use the names of corresponding JavaScript built-ins. When a
Type shadows one, access the JavaScript built-in through globalThis, such
as globalThis.String or globalThis.Date.
Evolu Type supports Standard Schema and
requires TypeScript 7+ with exactOptionalPropertyTypes enabled.
Examples
Define a domain object with a custom Age Type, then validate unknown input:
import {
assertEqual,
Data,
assertErr,
assertOk,
assertType,
Number,
NonEmptyTrimmedString100,
brand,
finite,
int,
lessThan,
nonNaN,
nonNegative,
object,
type Brand,
type InferErrors,
type InferType,
} from "@evolu/common";
// Age and its parent Types are predefined by Evolu. They are reconstructed
// here to reveal every constraint behind a seemingly simple domain value.
const NonNaNNumber = nonNaN(Number);
const FiniteNumber = finite(NonNaNNumber);
const Int = int(FiniteNumber);
const NonNegativeInt = nonNegative(Int);
const Age = brand("Age", lessThan(200)(NonNegativeInt));
type Age = typeof Age.Output;
assertType<
number &
Brand<"NonNaN"> &
Brand<"Finite"> &
Brand<"Int"> &
Brand<"NonNegative"> &
Brand<"LessThan200"> &
Brand<"Age">,
Age
>();
const User = object({
name: NonEmptyTrimmedString100,
age: Age,
});
interface User extends InferType<typeof User> {}
const value: unknown = { name: "Ada", age: 37 };
const user = User.fromUnknown(value);
assertOk(user, { name: "Ada", age: 37 });
assertType<typeof User.Output, typeof user.value>();
const invalidUser = User.fromUnknown({ name: "Ada", age: 37.5 });
assertErr(invalidUser);
// InferErrors includes every structured error User.fromUnknown can return.
assertType<InferErrors<typeof User>, typeof invalidUser.error>();
assertType(Data, invalidUser.error);
assertEqual(invalidUser.error, {
type: "Object",
reason: {
kind: "Properties",
errors: {
age: { type: "Int", value: 37.5 },
},
},
});
A Type can format its structured errors into user-facing messages:
import { assertEqual, assertType, Data, assertErr, Age } from "@evolu/common";
const age = Age.fromUnknown(37.5);
assertErr(age);
assertType(Data, age.error);
assertEqual(age.error, { type: "Int", value: 37.5 });
assertEqual(
Age.formatError(age.error),
"The value 37.5 must be a safe integer.",
);
Use localizeTypes to derive Types with localized messages without changing validation behavior.
One of Evolu Type's strongest features is typed from boundaries. A value
producer, such as a form input, carries the precise constraints it
guarantees, and TypeScript checks them against the consuming domain field.
Unlike validation from unknown or string, this checks the contract
between the producer and consumer, not merely whether the current value
passes:
import {
assertOk,
assertType,
NonEmptyTrimmedString100,
NonEmptyTrimmedString1000,
object,
trim,
type MaxLengthError,
type MinLengthError,
type Result,
type TrimmedString,
} from "@evolu/common";
const Todo = object({ title: NonEmptyTrimmedString100 });
// This is type-checked: Todo.from expects NonEmptyTrimmedString100.
const title = NonEmptyTrimmedString100.orThrow("Buy milk");
assertOk(Todo.from({ title }), { title });
// Imagine the UI input component is changed to allow longer titles.
// TypeScript rejects the mismatch, so users never see a save error
// for a title the UI accepts but the domain cannot save.
const longerTitle = NonEmptyTrimmedString1000.orThrow("Buy milk");
// @ts-expect-error MaxLength1000 does not guarantee MaxLength100.
Todo.from({ title: longerTitle });
// Imagine a UI input component that returns TrimmedString.
// from.parent.parent connects it to the domain field and validates the
// remaining constraints.
const titleFromTrimmingInput: TrimmedString = trim(" Buy milk ");
const validatedTitle = Todo.props.title.from.parent.parent(
titleFromTrimmingInput,
);
// No "not a string" or "not trimmed" errors: the input guarantees both.
assertType<
Result<NonEmptyTrimmedString100, MaxLengthError<100> | MinLengthError<1>>,
typeof validatedTitle
>();
assertOk(validatedTitle, "Buy milk");
Evolu includes dozens of predefined Types and Type factories. Use Types such as Age, PositiveInt, DateIso, NonEmptyTrimmedString100, Base64Url, and Json directly. Build domain Types with factories such as brand, typed, minLength, maxLength, array, object, union, templateLiteral, transform, discriminatedUnion, and json.
Guarantees
Evolu Type validates values; it does not defend against adversarial
JavaScript such as malicious Proxies, mutation during validation, throwing
traps, forged built-ins, or code deliberately bypassing TypeScript with any
or casts.
Evolu Type trusts application code and audited dependencies. Untrusted code can cause harm far beyond validation and must not run in the application. Defending against it would add complexity without creating a meaningful security boundary.
Runtime assertions still detect accidental developer errors that TypeScript cannot express. They are correctness checks, not defenses against malicious code.
Evolu does not support subclassing native JavaScript objects. Such subclasses can be classified as their reported built-in representation, but their behavior is unspecified.
FAQ
What does a Type represent?
A Type is a lawful, pure codec for an exact semantic domain:
Input ── partial decode ──▶ Output
CanonicalInput ◀─── total encode ─── Output
CanonicalInput ⊆ Input
Read each line in the direction of its arrowhead. Input is the complete
typed decoding boundary, including candidates that validation can reject and
noncanonical representations that decoding can normalize. Output is the
validated semantic value. CanonicalInput is the statically known subtype of
Input returned by the complete to operation. It can be wider than the
values actually emitted when a refinement follows an arbitrary transformation
because TypeScript cannot determine which values its encoder returns for the
narrowed Output. fromUnknown and the from operations decode; to
encodes.
A lawful Type round-trips every Output:
fromUnknown(to(output)) ≈ ok(output)
Encoding can canonicalize a valid Input:
"0042" ──decode──▶ 42 ──encode──▶ "42"
Once canonicalized, repeating the decode-encode cycle must preserve that representation:
"42" ──decode──▶ 42 ──encode──▶ "42"
Here decode means running the complete decoding pipeline, as fromUnknown
does, and ≈ means equality appropriate for the semantic domain. Validation
refinements, Array Types, and
Object Types preserve these laws when their contained
Types do. A union additionally requires compatible dispatch: it
encodes through the first member matching the Output and decodes through the
first member accepting the Input. Member ordering is lawful only when those
choices agree semantically. Encoded representations can overlap even when
member Output types are disjoint.
When encoding returns a refined value unchanged, the refinement can narrow
CanonicalInput without changing its JavaScript representation. For example,
FiniteNumber has number as its Input, while its Output and
CanonicalInput are FiniteNumber: decoding can reject non-finite number
candidates, and encoding only receives validated finite Outputs. A
transformation can change the representation entirely. For
Int64FromInt64String, Input is string, Output is Int64, and
CanonicalInput is Int64String. Structural Type factories derive their
CanonicalInput recursively from their contained Types.
Why is to total?
Suppose a Type accepts only strings containing decimal digits and decodes
them to JavaScript numbers. Parsing "42" is possible, but the Type cannot
lawfully declare its Output as number:
digits-only string ──partial decode──▶ number
digits-only string ◀─── total encode ── number // impossible
number also contains negative and fractional numbers, NaN, positive and
negative infinity, and -0. None of those values has a digits-only
representation, so to could not encode every valid Output.
One lawful design narrows the Output to the exact representable domain:
digits-only string ──partial decode──▶ NonNegativeSafeInteger
digits-only string ◀─── total encode ── NonNegativeSafeInteger
"0042" ──decode──▶ 42 ──encode──▶ "42"
Another lawful design keeps number as the Output but expands the Input
representation to include a canonical string for every number, including
"NaN", "Infinity", "-Infinity", and "-0", as well as negative and
fractional numbers.
The same principle applies when converting between two representations. Give
each representation its own Type with the same exact Output. For example, a
string representation and a number representation can both decode to the
shared SafeInteger domain:
string ──partial decode──▶ SafeInteger
string ◀─── total encode ── SafeInteger
number ──partial decode──▶ SafeInteger
number ◀─── total encode ── SafeInteger
Conversion decodes the source representation, then total-encodes the shared Output into the target representation. If no lossless shared domain exists, the operation is a partial conversion, migration, or policy decision and should be an explicit function returning Result, not a Type transformation.
Why can a typed operation throw?
TypeScript proves structural assignability, but it cannot describe every runtime invariant. For example, it cannot express whether an object property is own, enumerable, or a data property. It also permits a wider object with excess properties where a narrower object type is expected.
fromUnknown treats such invalid external values as input data and returns a
typed error. Typed boundaries instead assert the domain promised by their
parameter type. If application code claims an accessor-backed object or an
object with excess properties is an Object Output, the assertion throws
because the application contract is broken. orThrow and orNull preserve
the assertion at their typed Input boundary, then apply getOrThrow
or getOrNull only to validation failures returned by the remaining
pipeline.
Consequently, structural representation errors such as sparse Arrays, accessors, and excess properties normally do not enter user-facing validation in typed application flows. They violate the producer's declared contract and throw as developer errors. At a genuinely unknown boundary, such as a schema-authoring tool, import, or external protocol, the same issues are legitimate typed validation errors and their formatter messages are useful.
This distinction applies to data failures. Any Type operation, including
fromUnknown, can throw when trusted Type-declaration code, such as a
successful transformation callback, violates its declared contract.
Materialize accessor values into plain data, remove properties the Type does
not represent, or use a different Type. Silently discarding excess data would
make the code constructing it dead while appearing to encode it successfully.
One exact Object policy also keeps Output membership independent of parsing
configuration. Exact structural policies also keep Output membership
independent of whether a transformation happens to allocate a new value.
Evolu Type therefore does not invoke accessors, discard excess properties, or
make to fallible. This keeps to total for every legitimate Output and
lets transformations compose without an encoding-error channel.
How should values from another realm be handled?
Values returned by legacy code or another realm can still be uncertain and should be validated. Realm-neutral Types accept an otherwise legitimate representation without requiring conversion merely because its JavaScript built-ins belong to another realm.
When an application trusts both the producer and its return contract, expose
that contract as an accurate TypeScript type and use the typed value
directly. If the boundary returns unknown, validate it instead of bypassing
the boundary with a cast. Use a specialized Type or explicit transformation
when the producer uses a different representation that needs adaptation or
normalization.
Why doesn't Evolu Type extract data from rich objects?
Some validation libraries parse an object's data projection. An imaginary
validation library can enumerate own enumerable string properties and decode
them into a fresh plain object. That lets a class instance decode as plain
data while its prototype and methods are ignored. The same general policy can
treat a Date or Map as an empty Record and can invoke enumerable getters.
This is a coherent but intentionally forgiving normalization model.
Evolu Type validates exactly the runtime representation defined by each Type;
it does not implicitly project one representation into another. The
predefined Object defines an open plain-object representation with
unknown values, object defines a closed plain-object representation,
and record defines a plain-dictionary representation whose complete
set of own properties are its entries. Their realm-neutral plain-object rule
uses isPlainObject: it accepts a null prototype or an immediate root
prototype with own hasOwnProperty and isPrototypeOf properties. A custom
root prototype with the same shape can therefore be classified as plain;
other custom prototypes and class instances are rejected. This heuristic
assumes trusted JavaScript and is not a security boundary. Every property
must be an enumerable data property; inherited members are not entries, while
accessors and hidden properties are invalid instead of being invoked or
ignored. array similarly defines a dense sequence whose only own
properties are length and its indexed data properties; tuple applies
the same representation rules with a fixed length and a distinct Type for
each position. Only an explicit transform changes the representation.
Consequently, is tests exact Output membership and to stays total for
valid Outputs.
Why is JsonValue stricter than JSON.stringify?
JSON.stringify is a forgiving data projection. It can invoke toJSON and
accessors, discard object properties, replace unsupported array elements and
non-finite numbers with null, and normalize -0 to 0. Those rules are
useful for ordinary serialization, but they do not preserve an exact value.
JsonValue instead defines data that is already represented as data.
Invalid runtime behavior and values are rejected rather than interpreted or
silently discarded. Its encoder is total and stack-safe for every valid
Output, and JsonValueFromJson preserves the semantic value when it is
encoded and decoded, including JavaScript's distinction between -0 and 0.
Use an explicit transformation before this boundary when a projection or
other normalization is desired.
Why are Types pure and synchronous?
A Type describes data meaning, not work. Time, I/O, dependencies, external state, authorization, and other contextual decisions belong in a Task. Use a Type to decode the data required by that work, then pass the decoded value to a Task. A pure synchronous conversion that can fail can be an ordinary function returning Result.
Keeping those responsibilities separate prevents Evolu Type from becoming a hidden application workflow. It also keeps validation deterministic, dependency-free, immediately composable, and straightforward to test.
What if only decoding is needed?
Use fromUnknown for unknown data. For typed application data, call from
at the boundary its input type proves, or use orThrow or orNull for a
flat conversion from Input. The canonical to encoder still keeps the Type
lawful and composable with transformations and structural Types. A genuinely
irreversible operation is a separate function or Task, not a Type
transformation.
Core
| Name | Description |
|---|---|
| AnyType | Any concrete Type, regardless of its particular type parameters. |
| EvoluTypeError | Error returned when EvoluType rejects a value. |
| Type | A runtime representation of a TypeScript type, including its encoded input, semantic output, structured errors, and canonical encoding. |
| TypeError | A plain structured error produced by a Type operation. |
| TypeNode | The common structural shape of every Type, with its specific type parameters erased. |
| TypeValueError | A structured error that directly describes a rejected value. |
| ValidationOptions | Configures how container Type operations report errors. |
| InferErrors | The union of errors a Type can return from fromUnknown. |
| InferType | Extracts the Output of a Type. |
| TypeErrorFormatter | Formats a structured TypeError as a human-readable message. |
| TypeName | A capitalized name identifying a Type node. |
| EvoluType | A Type validating Evolu Type declarations. |
| assertType | Asserts exact compile-time type equality or that a value belongs to a Type Output domain. |
Construction
| Name | Description |
|---|---|
| BrandType | The Type returned by brand. |
| TransformOutputError | Wraps an error produced by the output Type of transform. |
| TransformType | The Type returned by transform. |
| BrandFactory | Reusable factory for creating a Type with a Brand. |
| TransformError | An error produced by transform while decoding or validating its output. |
| ValidateBrandFactoryNumber | Numeric parameter preserving literal types in a BrandFactory. |
| brand | Branded Type. |
| createType | Custom Type. |
| transform | Transform Type. |
Base
| Name | Description |
|---|---|
| DataError | An error containing one or more issues found while validating a candidate as Data. |
| DataType | The root Type for Evolu Data. |
| InstanceOfError | Error returned when a value is not an instance of the expected constructor. |
| InstanceOfType | The Type returned by instanceOf. |
| NeverError | Error returned by Never for every value. |
| ObjectTag | Nominal evidence that a value has one object tag. |
| ObjectTagError | An error returned when an object does not report the expected tag. |
| ObjectTagType | The Type returned by objectTag. |
| TypeOfError | Error returned when typeof does not match the expected JavaScript type. |
| Data | Evolu's recursive platform-independent structured-cloneable data domain. |
| DataIssue | One issue found while validating a candidate as Data. |
| InstanceConstructor | A JavaScript class constructor accepted by instanceOf. |
| IsData | Returns whether a TypeScript type consists only of Data. |
| ArrayBuffer | A realm-neutral JavaScript ArrayBuffer Type for trusted values. |
| BigInt | A JavaScript bigint Type. |
| Boolean | A JavaScript boolean Type. |
| Data | Root Type for Data values. |
| Date | A realm-neutral JavaScript Date Type for trusted values. |
| Function | A JavaScript function Type. |
| Never | A Type rejecting every value. |
| Object | A Type for readonly plain objects with unknown property values. |
| Symbol | A JavaScript symbol Type. |
| Uint8Array | A realm-neutral JavaScript Uint8Array Type for trusted values. |
| Unknown | An infallible Type accepting every value. |
| instanceOf | Instance Type for one constructor. |
| objectTag | Realm-neutral Type trusting an object's reported tag. |
String
| Name | Description |
|---|---|
| Base64UrlError | Error returned when a string is not valid Base64Url text. |
| CapitalizedError | Error returned when capitalized rejects a string. |
| DateIsoError | Error returned when a string is not a canonical DateIso. |
| DateIsoFromDateError | Error returned when a Date cannot be represented as DateIso. |
| IdError | Error returned when a string is not a valid Id. |
| MnemonicError | Error returned when a string is not a valid English BIP39 Mnemonic. |
| NameError | Error returned when a string is not a valid Name. |
| RegexError | Error returned when a string does not match the regular expression supplied to regex. |
| TableId | The Type returned by id for one table. |
| TableIdError | Error returned when a string is not a valid Id for the expected table. |
| TrimmedError | Error returned when trimmed rejects a string. |
| Base64Url | Base64Url text without padding. |
| CapitalizedString | Capitalized String. |
| DateIso | Canonical ISO date-time String. |
| Digit | Decimal digit from "0" to "9". |
| Digit1To23 | Decimal string from "1" to "23". |
| Digit1To51 | Decimal string from "1" to "51". |
| Digit1To59 | Decimal string from "1" to "59". |
| Digit1To6 | Decimal string from "1" to "6". |
| Digit1To9 | Decimal digit from "1" to "9". |
| Digit1To99 | Decimal string from "1" to "99". |
| Id | Evolu Id: 16 bytes encoded as a 22-character Base64Url. |
| IdBytes | Binary representation of an Id. |
| Mnemonic | A valid English BIP39 mnemonic. |
| Name | A non-empty URL-safe name containing at most 64 UTF-16 code units. |
| NonEmptyTrimmedString | A non-empty TrimmedString. |
| NonEmptyTrimmedString100 | A NonEmptyTrimmedString with at most 100 UTF-16 code units. |
| NonEmptyTrimmedString1000 | A NonEmptyTrimmedString with at most 1,000 UTF-16 code units. |
| SimplePassword | A trimmed password containing between 8 and 64 UTF-16 code units. |
| TrimmedString | A String without surrounding whitespace. |
| UrlSafeString | Non-empty URL-safe String. |
| Base64Url | Base64Url text without padding. |
| capitalized | Capitalized Brand. |
| CapitalizedString | Capitalized String. |
| DateIso | Canonical ISO date-time String. |
| DateIsoFromDate | Safely transforms a Date into a canonical DateIso. |
| Digit | Decimal digit from "0" to "9". |
| Digit1To23 | Decimal string from "1" to "23". |
| Digit1To51 | Decimal string from "1" to "51". |
| Digit1To59 | Decimal string from "1" to "59". |
| Digit1To6 | Decimal string from "1" to "6". |
| Digit1To9 | Decimal digit from "1" to "9". |
| Digit1To99 | Decimal string from "1" to "99". |
| Id | Evolu Id: 16 bytes encoded as a 22-character Base64Url. |
| IdBytes | Binary representation of an Id. |
| idBytesTypeValueLength | Byte length of an IdBytes value. |
| Mnemonic | A valid English BIP39 mnemonic. |
| Name | A non-empty URL-safe name containing at most 64 UTF-16 code units. |
| NonEmptyTrimmedString | A non-empty TrimmedString. |
| NonEmptyTrimmedString100 | A NonEmptyTrimmedString with at most 100 UTF-16 code units. |
| NonEmptyTrimmedString1000 | A NonEmptyTrimmedString with at most 1,000 UTF-16 code units. |
| SimplePassword | A trimmed password containing between 8 and 64 UTF-16 code units. |
| String | A JavaScript string Type without additional constraints. |
| testName | Stable valid Name for tests and internal fixtures. |
| trimmed | String Brand without surrounding whitespace. |
| TrimmedString | A String without surrounding whitespace. |
| UrlSafeString | Non-empty URL-safe String. |
| base64UrlToUint8Array | Converts Base64Url to bytes. |
| createId | Creates a cryptographically random Id. |
| createIdAsUuidv7 | Creates an Id whose bytes use the UUID v7 timestamp layout. |
| createIdFromString | Deterministically creates an Id from the first 16 SHA-256 bytes. |
| id | Table-specific Id Type. |
| idBytesToId | Converts IdBytes to an Id. |
| idToIdBytes | Converts an Id to IdBytes. |
| length | Exact-length Brand for values whose length equals exact. |
| maxLength | Maximum-length Brand for values whose length is at most max. |
| minLength | Minimum-length Brand for values whose length is at least min. |
| regex | String Brand constrained by a regular expression. |
| trim | Trims a string and returns a TrimmedString. |
| uint8ArrayToBase64Url | Converts bytes to Base64Url. |
Number
| Name | Description |
|---|---|
| BetweenError | Error returned when between rejects a number. |
| DecimalStringError | Error returned when a string is not a canonical DecimalString. |
| FiniteError | Error returned when finite rejects a non-finite number. |
| GreaterThanError | Error returned when greaterThan rejects a number. |
| GreaterThanOrEqualToError | Error returned when greaterThanOrEqualTo rejects a number. |
| Int64Error | Error returned when a bigint is outside the signed 64-bit Int64 range. |
| Int64StringError | Error returned when a string is not a canonical Int64String. |
| IntError | Error returned when int rejects a number that is not a safe integer. |
| LessThanError | Error returned when lessThan rejects a number. |
| LessThanOrEqualToError | Error returned when lessThanOrEqualTo rejects a number. |
| MultipleOfError | Error returned when multipleOf rejects a number. |
| NegativeDecimalStringError | Error returned when negativeDecimalString rejects a decimal string. |
| NegativeError | Error returned when negative rejects a number. |
| NonNaNError | Error returned when nonNaN rejects NaN. |
| NonNegativeDecimalStringError | Error returned when nonNegativeDecimalString rejects a decimal string. |
| NonNegativeError | Error returned when nonNegative rejects a number. |
| NonPositiveDecimalStringError | Error returned when nonPositiveDecimalString rejects a decimal string. |
| NonPositiveError | Error returned when nonPositive rejects a number. |
| PositiveDecimalStringError | Error returned when positiveDecimalString rejects a decimal string. |
| PositiveError | Error returned when positive rejects a number. |
| UInt64Error | Error returned when a bigint is outside the unsigned 64-bit UInt64 range. |
| Age | A person's age as a NonNegativeInt less than 200. |
| DecimalString | Canonical string representation of a signed base-10 decimal value. |
| FiniteNumber | Finite Number. |
| Int | Safe integer FiniteNumber. |
| Int64 | Signed 64-bit BigInt. |
| Int64String | Decimal string representation of a signed Int64. |
| NegativeDecimalString | Negative DecimalString. |
| NegativeInt | Negative Int. |
| NegativeNumber | Negative Number. |
| NonNaNNumber | Number other than NaN; infinities are allowed. |
| NonNegativeDecimalString | Non-negative DecimalString. |
| NonNegativeFiniteNumber | Non-negative FiniteNumber. |
| NonNegativeInt | Non-negative Int. |
| NonNegativeNumber | Non-negative Number. |
| NonPositiveDecimalString | Non-positive DecimalString. |
| NonPositiveInt | Non-positive Int. |
| NonPositiveNumber | Non-positive Number. |
| PositiveDecimalString | Positive DecimalString. |
| PositiveFiniteNumber | Positive FiniteNumber. |
| PositiveInt | Positive Int. |
| PositiveNumber | Positive Number. |
| Ratio | Finite Number from zero to one, inclusive. |
| UInt64 | Unsigned 64-bit BigInt. |
| Age | A person's age as a NonNegativeInt less than 200. |
| DecimalString | Canonical string representation of a signed base-10 decimal value. |
| finite | Number Brand requiring a finite value. |
| FiniteNumber | Finite Number. |
| int | Safe integer Brand. |
| Int | Safe integer FiniteNumber. |
| Int64 | Signed 64-bit BigInt. |
| Int64FromInt64String | Transforms an Int64String into an Int64. |
| Int64String | Decimal string representation of a signed Int64. |
| maxPositiveInt | Maximum PositiveInt value. |
| negative | Number Brand requiring a value less than zero. |
| negativeDecimalString | DecimalString Brand requiring a value less than zero. |
| NegativeDecimalString | Negative DecimalString. |
| NegativeInt | Negative Int. |
| NegativeNumber | Negative Number. |
| nonNaN | Number Brand requiring a value other than NaN. |
| NonNaNNumber | Number other than NaN; infinities are allowed. |
| nonNegative | Number Brand requiring a value greater than or equal to zero. |
| nonNegativeDecimalString | DecimalString Brand requiring a value greater than or equal to zero. |
| NonNegativeDecimalString | Non-negative DecimalString. |
| NonNegativeFiniteNumber | Non-negative FiniteNumber. |
| NonNegativeInt | Non-negative Int. |
| NonNegativeNumber | Non-negative Number. |
| nonPositive | Number Brand requiring a value less than or equal to zero. |
| nonPositiveDecimalString | DecimalString Brand requiring a value less than or equal to zero. |
| NonPositiveDecimalString | Non-positive DecimalString. |
| NonPositiveInt | Non-positive Int. |
| NonPositiveNumber | Non-positive Number. |
| Number | A JavaScript number, including NaN, Infinity, and -Infinity. |
| onePositiveInt | Minimum PositiveInt value. |
| positive | Number Brand requiring a value greater than zero. |
| positiveDecimalString | DecimalString Brand requiring a value greater than zero. |
| PositiveDecimalString | Positive DecimalString. |
| PositiveFiniteNumber | Positive FiniteNumber. |
| PositiveInt | Positive Int. |
| PositiveNumber | Positive Number. |
| Ratio | Finite Number from zero to one, inclusive. |
| UInt64 | Unsigned 64-bit BigInt. |
| zeroNonNegativeInt | Minimum NonNegativeInt value. |
| between | Number Brand requiring a value within an inclusive range. |
| greaterThan | Number Brand requiring a value greater than min. |
| greaterThanOrEqualTo | Number Brand requiring a value greater than or equal to min. |
| lessThan | Number Brand requiring a value less than max. |
| lessThanOrEqualTo | Number Brand requiring a value less than or equal to max. |
| multipleOf | Number Brand requiring an exact decimal multiple of divisor. |
Collection
| Name | Description |
|---|---|
| ArrayAccessorIssue | An array element defined by an accessor instead of a data property. |
| ArrayExcessPropertyIssue | An own array property other than length or an indexed element. |
| ArrayHoleIssue | A missing array element. |
| ArrayNotArrayError | Error returned when an array input is not an array. |
| ArrayType | The homogeneous readonly-array Type returned by array. |
| LengthError | Error returned when length rejects a value. |
| MapExcessPropertyIssue | An own property found on a Map value. |
| MapKeyCollisionIssue | Two map keys that decode to the same output key. |
| MapNotMapError | Error returned when a map input is not a Map. |
| MapType | The readonly-map Type returned by map. |
| MaxLengthError | Error returned when maxLength rejects a value. |
| MinLengthError | Error returned when minLength rejects a value. |
| SetExcessPropertyIssue | An own property found on a Set value. |
| SetNotSetError | Error returned when a set input is not a Set. |
| SetType | The homogeneous readonly-set Type returned by set. |
| TupleAccessorIssue | An accessor element in a tuple. |
| TupleExcessPropertyIssue | An undeclared own property in a tuple. |
| TupleHoleIssue | A missing indexed element in a tuple. |
| TupleInvalidLengthError | An error returned when a tuple input has the wrong length. |
| TupleNotArrayError | An error returned when a tuple input is not an Array. |
| TupleType | The fixed-length heterogeneous Type returned by tuple. |
| ArrayElementIssue | An invalid array element and its index. |
| ArrayElementsError | An array error containing element errors from a typed boundary. |
| ArrayError | Error returned by array for a non-array value or invalid array items. |
| ArrayIssue | One structural or element issue found by array. |
| ArrayItemsError | An array error containing structural or element issues. |
| MapEntriesError | Entry errors returned by a map operation. |
| MapError | Error returned while validating a map and its entries. |
| MapIssue | An invalid key, value, or structure in a map. |
| MapKeyIssue | An invalid key and its entry index in a map. |
| MapValueIssue | An invalid value and its entry index in a map. |
| SetElementIssue | An invalid Set element and its iteration index. |
| SetElementsError | A set error containing element errors from a typed boundary. |
| SetError | Error returned by set for a non-Set value or invalid Set items. |
| SetItemsError | A set error containing structural or element issues. |
| TupleElementIssue | An error returned by one element Type in a tuple. |
| TupleElementsError | Element errors possible after a typed tuple boundary was asserted. |
| TupleError | An error returned while validating a tuple. |
| TupleIssue | One structural or element issue found in a tuple. |
| TupleItemsError | An error containing structural or element issues found in a tuple. |
| array | Array Type. |
| length | Exact-length Brand for values whose length equals exact. |
| map | Map Type whose keys and values must match their respective Types. |
| maxLength | Maximum-length Brand for values whose length is at most max. |
| minLength | Minimum-length Brand for values whose length is at least min. |
| set | Set Type whose every element must match one Type. |
| tuple | Tuple Type. |
Objects
| Name | Description |
|---|---|
| ObjectError | An error returned while validating an object and its properties. |
| ObjectExcessPropertyError | An error returned for an input property outside an Object Type's allowed key domain. |
| ObjectMissingPropertyError | An error returned when a required object property is absent. |
| ObjectNotObjectError | An error returned when an object input is not an object. |
| ObjectPropertiesError | An error returned while validating the properties of an object. |
| ObjectPropertyAccessError | An error returned when a present object property is not represented as an enumerable data property. |
| ObjectUnexpectedPrototypeError | An error returned when an object input falls outside its supported plain-object prototype boundary. |
| OptionalProperty | An optional property used to construct an object Type. |
| RecordAccessorIssue | An accessor property rejected by record. |
| RecordCollisionIssue | Two record keys that decode to the same output key. |
| RecordNonEnumerableIssue | A non-enumerable property rejected by record. |
| RecordNotPlainRecordError | Error returned when a record input is not a plain object. |
| RecordNotRecordError | Error returned when a record input is not an object. |
| RecordType | The Type returned by record. |
| NullableToOptionalProps | Maps object properties whose Union Type includes Null to optional properties. |
| ObjectProps | Properties used to construct an object Type. |
| ObjectType | The Type returned by object. |
| PartialObjectProps | Maps every required object property Type to an optional property. |
| RecordEntriesError | Entry errors returned by a record operation. |
| RecordError | Error returned while validating a record and its entries. |
| RecordIssue | An invalid key, value, or property structure in a record. |
| RecordKeyIssue | An invalid key and its source property key in a record. |
| RecordStructuralIssue | A property-structure issue returned by record. |
| RecordValueIssue | An invalid value and its property key in a record. |
| nullableToOptional | Object Type making every property whose Union Type includes Null optional. |
| object | Plain object Type. |
| omit | Object Type without the selected declared properties. |
| optional | Optional object property. |
| partial | Object Type with every property optional. |
| record | Record Type. |
Unions
| Name | Description |
|---|---|
| LiteralError | Error returned when a value does not equal the expected literal. |
| LiteralType | The Type returned by literal. |
| UnionMemberError | An error returned by one union member and its index. |
| UnionType | The Type returned by union. |
| UnionError | Error returned when every member of a union rejects an input. |
| UnionInputType | A root Type validating the encoded Inputs accepted by union. |
| Null | Literal Type accepting only null. |
| Undefined | Literal Type accepting only undefined. |
| literal | Literal Type. |
| nullishOr | Union Type containing the supplied Type, null, and undefined. |
| nullOr | Union Type containing the supplied Type and null. |
| undefinedOr | Union Type containing the supplied Type and undefined. |
| union | Union Type. |
Template literals
| Name | Description |
|---|---|
| TemplateLiteralError | Error returned when a string does not match a template literal declaration. |
| TemplateLiteralParserType | The parsing Type returned by templateLiteralParser. |
| TemplateLiteralType | The validating string Type returned by templateLiteral. |
| templateLiteral | Template literal Type for validation. |
| templateLiteralParser | Template literal Type that parses canonical strings into Tuples. |
Discriminated unions
| Name | Description |
|---|---|
| DiscriminatedUnionDiscriminatorError | An error returned when no member of discriminatedUnion matches. |
| DiscriminatedUnionMemberIssue | A selected-member issue returned by discriminatedUnion. |
| DiscriminatedUnionObjectError | An error returned when a value cannot be routed through Object. |
| DiscriminatedUnionPropertyAccessError | An error returned when the discriminator for discriminatedUnion is not an own enumerable data property. |
| DiscriminatedUnionType | The routed Type returned by discriminatedUnion. |
| Typed | A TypeScript interface with a literal type property. |
| DiscriminatedUnionError | An error returned while selecting a member in discriminatedUnion. |
| DiscriminatedUnionInputType | A root Type validating Inputs accepted by discriminatedUnion. |
| DiscriminatedUnionMemberError | An error returned by the member selected by discriminatedUnion. |
| ExtractTyped | Extracts members of a Typed Output union by their type literal. |
| TypedType | The ObjectType returned by typed. |
| discriminatedUnion | Discriminated union Type. |
| typed | Creates an ObjectType with a literal type property. |
Results
| Name | Description |
|---|---|
| UnknownNextResult | A nextResult Type with unknown value, error, and done components. |
| UnknownResult | A result Type for Result<unknown, unknown>. |
| UnknownNextResult | A nextResult Type with unknown value, error, and done components. |
| UnknownResult | A result Type for Result<unknown, unknown>. |
| nextResult | Creates a Type for producer Results with value, error, or done outcomes. |
| result | Creates a Type for Result values. |
Recursive
| Name | Description |
|---|---|
| LazyType | A deferred Type with an explicit recursive type declaration. |
| lazy | Creates a lazy Type for recursive definitions. |
JSON
| Name | Description |
|---|---|
| JsonError | An error returned when a string does not contain valid JSON text. |
| JsonObject | An exact JSON object containing only JsonValue properties. |
| JsonObjectInput | A candidate JSON object before exact runtime validation. |
| JsonObjectType | The exact top-level JSON object Type. |
| JsonValueError | An error containing one or more issues found while validating a candidate as an exact JsonValue. |
| JsonValueType | The exact root Type of in-memory JSON data values. |
| Json | A String Brand proving that its exact text parses to JsonValue. |
| JsonArray | An exact JSON array containing only JsonValue elements. |
| JsonArrayInput | A candidate JSON array before exact runtime validation. |
| JsonValue | An exact in-memory JSON data value. |
| JsonValueInput | A candidate JSON value before exact runtime validation. |
| JsonValueIssue | One issue found while validating a candidate as an exact JsonValue. |
| Json | A String Brand proving that its exact text parses to JsonValue. |
| JsonArray | Exact top-level JSON array Type. |
| JsonObject | Exact top-level JSON object Type. |
| JsonValue | Exact root Type for JsonValue data trees. |
| JsonValueFromJson | Transformation Type that parses Json into JsonValue. |
| json | Branded Json Type and conversions for another Type. |
| jsonToJsonValue | Converts proven Json text to an exact JsonValue. |
| jsonValueToJson | Converts an exact JsonValue to canonical Json text. |
Localization
| Variable | Description |
|---|---|
| localizeTypes | Creates localized copies of selected Type declarations. |