API reference@evolu/common › Type

Runtime type validation, parsing, and branded types.

Base Types

VariableDescription
BigInt-
Boolean-
DateJavaScript Date.
Function-
JsonValueJSON-compatible value: string, FiniteNumber, boolean, null, JsonArray, or JsonObject.
Null-
Number-
String-
Uint8Array-
Undefined-
Unknown-

Base factories

FunctionDescription
arrayArray of a specific Type.
baseBase Type.
brandBranded Type.
instanceOfinstanceof Type.
literalLiteral Type.
nullishOrunion(undefined, null, T) Type.
nullOrunion(null, T) Type.
objectObject Type.
recordRecord of a key Type and value Type.
recursiveRecursive Type.
setSet of a specific Type.
tupleTuple Type.
undefinedOrunion(undefined, T) Type.
unionUnion Type.

Composite factories

NameDescription
UnknownNextResultA nextResult type for NextResult<unknown, unknown, unknown>.
UnknownResultA result type for Result<unknown, unknown>.
UnknownNextResultA nextResult type for NextResult<unknown, unknown, unknown>.
UnknownResultA result type for Result<unknown, unknown>.
nextResultCreates a Type for NextResult with three outcomes.
resultCreates a Type for Result values.

String

NameDescription
Base64UrlBase64Url without padding.
CurrencyCodeA three-letter ISO 4217 currency code (e.g., USD, EUR).
DateIsoISO 8601 date-time string.
IdEvolu Id: 16 bytes encoded as a 22‑character Base64Url string.
Int64StringStringified Int64.
JsonJSON-string Type.
MnemonicThe 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.
NameAlphanumeric string for naming in file systems, URLs, and identifiers.
NonEmptyString-
NonEmptyString100-
NonEmptyString1000-
NonEmptyTrimmedString-
NonEmptyTrimmedString100-
NonEmptyTrimmedString1000-
SimplePasswordTrimmed string between 8 and 64 characters, branded as SimplePassword.
String100-
String1000-
TrimmedStringTrimmed string
TrimmedString100-
TrimmedString1000-
UrlSafeStringURL-safe string.
Base64UrlBase64Url without padding.
CurrencyCodeA three-letter ISO 4217 currency code (e.g., USD, EUR).
DateIsoISO 8601 date-time string.
IdEvolu Id: 16 bytes encoded as a 22‑character Base64Url string.
Int64StringStringified Int64.
JsonJSON-string Type.
lengthExact length.
maxLengthMaximum length.
minLengthMinimum length.
MnemonicThe 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.
NameAlphanumeric string for naming in file systems, URLs, and identifiers.
NonEmptyString-
NonEmptyString100-
NonEmptyString1000-
NonEmptyTrimmedString-
NonEmptyTrimmedString100-
NonEmptyTrimmedString1000-
regexString matching a regular expression.
SimplePasswordTrimmed string between 8 and 64 characters, branded as SimplePassword.
String-
String100-
String1000-
trimmedTrimmed string.
TrimmedStringTrimmed string
TrimmedString100-
TrimmedString1000-
UrlSafeStringURL-safe string.
createIdFromStringCreates an Id from a string using SHA-256.
idCreates a branded Id Type for a table's primary key.

Number

NameDescription
FiniteNumberFinite number.
IntInteger within the safe range of JavaScript numbers.
Int6464-bit signed integer.
NegativeIntNegative integer (< 0).
NegativeNumberNegative number (< 0).
NonNaNNumber-
NonNegativeIntNon-negative integer (≥ 0).
NonNegativeNumberNon-negative number (≥ 0).
NonPositiveIntNon-positive integer (≤ 0).
NonPositiveNumberNon-positive number (≤ 0).
PositiveIntPositive integer (> 0).
PositiveNumberPositive number (> 0).
betweenNumber within a range, inclusive.
finiteFinite number.
FiniteNumberFinite number.
greaterThanNumber greater than a specified value.
greaterThanOrEqualToNumber ≥ a specified value.
IntInteger within the safe range of JavaScript numbers.
Int6464-bit signed integer.
lessThanNumber less than a specified value.
lessThanOrEqualToNumber ≤ a specified value.
multipleOfNumber that is a multiple of a divisor.
negativeNegative number (< 0).
NegativeIntNegative integer (< 0).
NegativeNumberNegative number (< 0).
nonNaNNumber that is not NaN.
NonNaNNumber-
nonNegativeNon-negative number (≥ 0).
NonNegativeIntNon-negative integer (≥ 0).
NonNegativeNumberNon-negative number (≥ 0).
nonPositiveNon-positive number (≤ 0).
NonPositiveIntNon-positive integer (≤ 0).
NonPositiveNumberNon-positive number (≤ 0).
positivePositive number (> 0).
PositiveIntPositive integer (> 0).
PositiveNumberPositive number (> 0).

Array

NameDescription
JsonArrayJSON-compatible array of JsonValue elements.
JsonArrayJSON-compatible array of JsonValue elements.
lengthExact length.
maxLengthMaximum length.
minLengthMinimum length.
arrayArray of a specific Type.

Object

NameDescription
JsonObjectJSON-compatible object with string keys and JsonValue values.
nullableToOptionalConverts 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.
objectObject Type.
omitCreate a new object Type by omitting some keys.
partialCreates a partial object type where all properties are optional.
recordRecord of a key Type and value Type.

Utilities

NameDescription
AnyTypeA Type with all type parameters set to any.
BrandFactoryHelper type for Type Factory that creates a branded Type.
InferErrorExtracts the specific error type from a Type.
InferErrorsExtracts all error types from a Type.
InferInputExtracts the input type from a Type.
InferNameExtracts the name from a Type.
InferParentExtracts the parent type from a Type.
InferParentErrorExtracts the parent error type from a Type.
InferTypeExtracts the type from a Type.
MergeObjectTypeErrorsMerge Error and ParentError into one ObjectError so tooltips and error messages are easier to read.
TypeErrorsUnion 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.
TypeNameUnique identifier for a Type.
createBaseTypeErrorFormatterCreates a formatter function for a base TypeError.
createFormatTypeErrorFormats Evolu Type errors into user-friendly messages.
createTypeErrorFormatterCreates a formatter function for TypeError.
isTypeChecks if the given value is an Type.
typeErrorToStandardSchemaIssuesConverts an Evolu TypeError to Standard Schema V1 issues format.

Functions

FunctionDescription
createIdCreates a random Id. This is the recommended default.
createIdAsUuidv7Creates an Id embedding timestamp bits (UUID v7 layout) before Base64Url encoding.
dateIsoToDate-
dateToDateIso-
formatArrayError-
formatObjectError-
formatObjectWithRecordError-
formatRecordError-
formatSetError-
formatSimplePasswordError-
formatTupleError-
formatUnionError-
idBytesToId-
idToIdBytes-
isOptionalTypeDetermines if a given type is an OptionalType.
isUnionType-
jsonCreates a branded JSON string Type and type-safe conversion functions for a given Type.
jsonToJsonValue-
jsonValueToJson-
optionalOptional Type.
parseJson-
trim-
typedCreates a runtime-validated typed object with a type discriminant.

Interfaces

InterfaceDescription
ArrayError-
ArrayTypeArrayType extends Type with an additional element property for reflection.
Base64UrlError-
BetweenError-
BigIntError-
BooleanError-
BrandTypeEvolu 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-
InstanceOfTypeEvolu 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-
LiteralTypeEvolu 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-
ObjectTypeObjectType extends Type with an additional props property for reflection.
ObjectWithRecordError-
ObjectWithRecordTypeObjectWithRecordType extends Type with additional props and record properties for reflection.
OptionalTypeEvolu 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-
RecordTypeRecordType extends Type with additional key and value properties for reflection.
RecursiveTypeEvolu 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-
SetTypeSetType extends Type with an additional element property for reflection.
StandardSchemaV1The Standard Schema interface.
StringError-
TableIdEvolu 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-
TupleTypeTupleType extends Type with an additional elements property for reflection.
TypeEvolu 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.
TypedBase interface for objects with a discriminant type property.
TypeError-
TypeErrorWithReason-
Uint8ArrayError-
UndefinedError-
UnionError-
UnionTypeUnionType extends Type with an additional members property for reflection.

Namespaces

NamespaceDescription
StandardSchemaV1-

Type Aliases

Type AliasDescription
IdBytesBinary representation of an Id.
IsUnionWithNull-
JsonArrayInput-
JsonValueValidated JSON-compatible value.
JsonValueError-
JsonValueInputJSON-compatible input value before validation.
NullableToOptionalProps-
NullTypeInMembers-
SimplePasswordError-
TransformNullable-
TypedTypeReturn type of typed.
TypeErrorFormatter-
UrlSafeStringError-

Variables

VariableDescription
base64UrlToUint8ArrayDecodes a Base64Url string to a Uint8Array.
EvoluTypeValidates that an unknown value is an Evolu Type (i.e., satisfies AnyType).
formatBase64UrlError-
formatBetweenError-
formatBigIntError-
formatBooleanError-
formatCurrencyCodeError-
formatDateIsoError-
formatFiniteError-
formatFunctionError-
formatGreaterThanError-
formatGreaterThanOrEqualToError-
formatIdError-
formatInstanceOfError-
formatInt64Error-
formatInt64StringError-
formatIntError-
formatIsTypeError-
formatJsonError-
formatLengthError-
formatLessThanError-
formatLessThanOrEqualToError-
formatLiteralError-
formatMaxLengthError-
formatMinLengthError-
formatMnemonicError-
formatMultipleOfError-
formatNegativeError-
formatNonNaNError-
formatNonNegativeError-
formatNonPositiveError-
formatNullError-
formatNumberError-
formatPositiveError-
formatRegexError-
formatStringError-
formatTableIdError-
formatTrimmedError-
formatUint8ArrayError-
formatUndefinedError-
IdBytesBinary representation of an Id.
idBytesTypeValueLength-
maxPositiveIntMaximum PositiveInt value (MAX_SAFE_INTEGER).
onePositiveIntPositiveInt value 1.
testName-
uint8ArrayToBase64UrlEncodes a Uint8Array to a Base64Url string.
zeroNonNegativeIntMinimum NonNegativeInt value (0).