API reference › @evolu/common › Type
Runtime type validation, parsing, and branded types.
Base Types
| Variable | Description |
|---|---|
| BigInt | - |
| Boolean | - |
| Date | JavaScript Date. |
| Function | - |
| JsonValue | JSON-compatible value: string, FiniteNumber, boolean, null, JsonArray, or JsonObject. |
| Null | - |
| Number | - |
| String | - |
| Uint8Array | - |
| Undefined | - |
| Unknown | - |
Base factories
| Function | Description |
|---|---|
| array | Array of a specific Type. |
| base | Base Type. |
| brand | Branded Type. |
| instanceOf | instanceof Type. |
| literal | Literal Type. |
| nullishOr | union(undefined, null, T) Type. |
| nullOr | union(null, T) Type. |
| object | Object Type. |
| record | Record of a key Type and value Type. |
| recursive | Recursive Type. |
| set | Set of a specific Type. |
| tuple | Tuple Type. |
| undefinedOr | union(undefined, T) Type. |
| union | Union Type. |
Composite factories
| Name | Description |
|---|---|
| UnknownNextResult | A nextResult type for NextResult<unknown, unknown, unknown>. |
| UnknownResult | A result type for Result<unknown, unknown>. |
| UnknownNextResult | A nextResult type for NextResult<unknown, unknown, unknown>. |
| UnknownResult | A result type for Result<unknown, unknown>. |
| nextResult | Creates a Type for NextResult with three outcomes. |
| result | Creates a Type for Result values. |
String
| Name | Description |
|---|---|
| Base64Url | Base64Url without padding. |
| CurrencyCode | A three-letter ISO 4217 currency code (e.g., USD, EUR). |
| DateIso | ISO 8601 date-time string. |
| Id | Evolu Id: 16 bytes encoded as a 22‑character Base64Url string. |
| Int64String | Stringified Int64. |
| Json | JSON-string Type. |
| Mnemonic | The mnemonic, also known as a "seed phrase," is a set of 12 words in a specific order chosen from a predefined list (BIP39). It provides a human-readable way to store a private key securely. The mnemonic is generated safely on the user's device using cryptographically secure random number generation, ensuring it remains private and unique. |
| Name | Alphanumeric string for naming in file systems, URLs, and identifiers. |
| NonEmptyString | - |
| NonEmptyString100 | - |
| NonEmptyString1000 | - |
| NonEmptyTrimmedString | - |
| NonEmptyTrimmedString100 | - |
| NonEmptyTrimmedString1000 | - |
| SimplePassword | Trimmed string between 8 and 64 characters, branded as SimplePassword. |
| String100 | - |
| String1000 | - |
| TrimmedString | Trimmed string |
| TrimmedString100 | - |
| TrimmedString1000 | - |
| UrlSafeString | URL-safe string. |
| Base64Url | Base64Url without padding. |
| CurrencyCode | A three-letter ISO 4217 currency code (e.g., USD, EUR). |
| DateIso | ISO 8601 date-time string. |
| Id | Evolu Id: 16 bytes encoded as a 22‑character Base64Url string. |
| Int64String | Stringified Int64. |
| Json | JSON-string Type. |
| length | Exact length. |
| maxLength | Maximum length. |
| minLength | Minimum length. |
| Mnemonic | The mnemonic, also known as a "seed phrase," is a set of 12 words in a specific order chosen from a predefined list (BIP39). It provides a human-readable way to store a private key securely. The mnemonic is generated safely on the user's device using cryptographically secure random number generation, ensuring it remains private and unique. |
| Name | Alphanumeric string for naming in file systems, URLs, and identifiers. |
| NonEmptyString | - |
| NonEmptyString100 | - |
| NonEmptyString1000 | - |
| NonEmptyTrimmedString | - |
| NonEmptyTrimmedString100 | - |
| NonEmptyTrimmedString1000 | - |
| regex | String matching a regular expression. |
| SimplePassword | Trimmed string between 8 and 64 characters, branded as SimplePassword. |
| String | - |
| String100 | - |
| String1000 | - |
| trimmed | Trimmed string. |
| TrimmedString | Trimmed string |
| TrimmedString100 | - |
| TrimmedString1000 | - |
| UrlSafeString | URL-safe string. |
| createIdFromString | Creates an Id from a string using SHA-256. |
| id | Creates a branded Id Type for a table's primary key. |
Number
| Name | Description |
|---|---|
| FiniteNumber | Finite number. |
| Int | Integer within the safe range of JavaScript numbers. |
| Int64 | 64-bit signed integer. |
| NegativeInt | Negative integer (< 0). |
| NegativeNumber | Negative number (< 0). |
| NonNaNNumber | - |
| NonNegativeInt | Non-negative integer (≥ 0). |
| NonNegativeNumber | Non-negative number (≥ 0). |
| NonPositiveInt | Non-positive integer (≤ 0). |
| NonPositiveNumber | Non-positive number (≤ 0). |
| PositiveInt | Positive integer (> 0). |
| PositiveNumber | Positive number (> 0). |
| between | Number within a range, inclusive. |
| finite | Finite number. |
| FiniteNumber | Finite number. |
| greaterThan | Number greater than a specified value. |
| greaterThanOrEqualTo | Number ≥ a specified value. |
| Int | Integer within the safe range of JavaScript numbers. |
| Int64 | 64-bit signed integer. |
| lessThan | Number less than a specified value. |
| lessThanOrEqualTo | Number ≤ a specified value. |
| multipleOf | Number that is a multiple of a divisor. |
| negative | Negative number (< 0). |
| NegativeInt | Negative integer (< 0). |
| NegativeNumber | Negative number (< 0). |
| nonNaN | Number that is not NaN. |
| NonNaNNumber | - |
| nonNegative | Non-negative number (≥ 0). |
| NonNegativeInt | Non-negative integer (≥ 0). |
| NonNegativeNumber | Non-negative number (≥ 0). |
| nonPositive | Non-positive number (≤ 0). |
| NonPositiveInt | Non-positive integer (≤ 0). |
| NonPositiveNumber | Non-positive number (≤ 0). |
| positive | Positive number (> 0). |
| PositiveInt | Positive integer (> 0). |
| PositiveNumber | Positive number (> 0). |
Array
| Name | Description |
|---|---|
| JsonArray | JSON-compatible array of JsonValue elements. |
| JsonArray | JSON-compatible array of JsonValue elements. |
| length | Exact length. |
| maxLength | Maximum length. |
| minLength | Minimum length. |
| array | Array of a specific Type. |
Object
| Name | Description |
|---|---|
| JsonObject | JSON-compatible object with string keys and JsonValue values. |
| nullableToOptional | Converts each “nullable” property (a union that includes Null) into an optional property. This means consumers can omit the property entirely, or set it to null, or set it to the non-null member of the union. |
| object | Object Type. |
| omit | Create a new object Type by omitting some keys. |
| partial | Creates a partial object type where all properties are optional. |
| record | Record of a key Type and value Type. |
Utilities
| Name | Description |
|---|---|
| AnyType | A Type with all type parameters set to any. |
| BrandFactory | Helper type for Type Factory that creates a branded Type. |
| InferError | Extracts the specific error type from a Type. |
| InferErrors | Extracts all error types from a Type. |
| InferInput | Extracts the input type from a Type. |
| InferName | Extracts the name from a Type. |
| InferParent | Extracts the parent type from a Type. |
| InferParentError | Extracts the parent error type from a Type. |
| InferType | Extracts the type from a Type. |
| MergeObjectTypeErrors | Merge Error and ParentError into one ObjectError so tooltips and error messages are easier to read. |
| TypeErrors | Union of all TypeErrors defined in the Type.ts file, including base type errors (e.g., StringError, NumberError), composite type errors (ArrayError, ObjectError), and optionally, user-defined extra errors. |
| TypeName | Unique identifier for a Type. |
| createBaseTypeErrorFormatter | Creates a formatter function for a base TypeError. |
| createFormatTypeError | Formats Evolu Type errors into user-friendly messages. |
| createTypeErrorFormatter | Creates a formatter function for TypeError. |
| isType | Checks if the given value is an Type. |
| typeErrorToStandardSchemaIssues | Converts an Evolu TypeError to Standard Schema V1 issues format. |
Functions
| Function | Description |
|---|---|
| createId | Creates a random Id. This is the recommended default. |
| createIdAsUuidv7 | Creates an Id embedding timestamp bits (UUID v7 layout) before Base64Url encoding. |
| dateIsoToDate | - |
| dateToDateIso | - |
| formatArrayError | - |
| formatObjectError | - |
| formatObjectWithRecordError | - |
| formatRecordError | - |
| formatSetError | - |
| formatSimplePasswordError | - |
| formatTupleError | - |
| formatUnionError | - |
| idBytesToId | - |
| idToIdBytes | - |
| isOptionalType | Determines if a given type is an OptionalType. |
| isUnionType | - |
| json | Creates a branded JSON string Type and type-safe conversion functions for a given Type. |
| jsonToJsonValue | - |
| jsonValueToJson | - |
| optional | Optional Type. |
| parseJson | - |
| trim | - |
| typed | Creates a runtime-validated typed object with a type discriminant. |
Interfaces
| Interface | Description |
|---|---|
| ArrayError | - |
| ArrayType | ArrayType extends Type with an additional element property for reflection. |
| Base64UrlError | - |
| BetweenError | - |
| BigIntError | - |
| BooleanError | - |
| BrandType | Evolu Type is like a type guard that returns typed errors (via Result) instead of throwing. We either receive a safely typed value or a composable typed error that tells us exactly why the validation failed. |
| BrandWithoutRefineError | - |
| CurrencyCodeError | - |
| DateIsoError | - |
| EvoluTypeError | - |
| FiniteError | - |
| FunctionError | - |
| GreaterThanError | - |
| GreaterThanOrEqualToError | - |
| IdError | - |
| InstanceOfError | - |
| InstanceOfType | Evolu Type is like a type guard that returns typed errors (via Result) instead of throwing. We either receive a safely typed value or a composable typed error that tells us exactly why the validation failed. |
| Int64Error | - |
| Int64StringError | - |
| IntError | - |
| JsonError | - |
| JsonObject | - |
| JsonObjectInput | - |
| LengthError | - |
| LessThanError | - |
| LessThanOrEqualToError | - |
| LiteralError | - |
| LiteralType | Evolu Type is like a type guard that returns typed errors (via Result) instead of throwing. We either receive a safely typed value or a composable typed error that tells us exactly why the validation failed. |
| MaxLengthError | - |
| MinLengthError | - |
| MnemonicError | - |
| MultipleOfError | - |
| NameError | - |
| NegativeError | - |
| NonNaNError | - |
| NonNegativeError | - |
| NonPositiveError | - |
| NullError | - |
| NumberError | - |
| ObjectError | - |
| ObjectType | ObjectType extends Type with an additional props property for reflection. |
| ObjectWithRecordError | - |
| ObjectWithRecordType | ObjectWithRecordType extends Type with additional props and record properties for reflection. |
| OptionalType | Evolu Type is like a type guard that returns typed errors (via Result) instead of throwing. We either receive a safely typed value or a composable typed error that tells us exactly why the validation failed. |
| PositiveError | - |
| RecordError | - |
| RecordType | RecordType extends Type with additional key and value properties for reflection. |
| RecursiveType | Evolu Type is like a type guard that returns typed errors (via Result) instead of throwing. We either receive a safely typed value or a composable typed error that tells us exactly why the validation failed. |
| RegexError | - |
| SetError | - |
| SetType | SetType extends Type with an additional element property for reflection. |
| StandardSchemaV1 | The Standard Schema interface. |
| StringError | - |
| TableId | Evolu Type is like a type guard that returns typed errors (via Result) instead of throwing. We either receive a safely typed value or a composable typed error that tells us exactly why the validation failed. |
| TableIdError | - |
| TrimmedError | - |
| TupleError | - |
| TupleType | TupleType extends Type with an additional elements property for reflection. |
| Type | Evolu Type is like a type guard that returns typed errors (via Result) instead of throwing. We either receive a safely typed value or a composable typed error that tells us exactly why the validation failed. |
| Typed | Base interface for objects with a discriminant type property. |
| TypeError | - |
| TypeErrorWithReason | - |
| Uint8ArrayError | - |
| UndefinedError | - |
| UnionError | - |
| UnionType | UnionType extends Type with an additional members property for reflection. |
Namespaces
| Namespace | Description |
|---|---|
| StandardSchemaV1 | - |
Type Aliases
| Type Alias | Description |
|---|---|
| IdBytes | Binary representation of an Id. |
| IsUnionWithNull | - |
| JsonArrayInput | - |
| JsonValue | Validated JSON-compatible value. |
| JsonValueError | - |
| JsonValueInput | JSON-compatible input value before validation. |
| NullableToOptionalProps | - |
| NullTypeInMembers | - |
| SimplePasswordError | - |
| TransformNullable | - |
| TypedType | Return type of typed. |
| TypeErrorFormatter | - |
| UrlSafeStringError | - |