| Level | Applies To | Example |
|---|---|---|
| **default** | built-in defaults for all Types | |
| **global** | all Types parsed after the config is applied | ```ts title="config.ts" import { configure } from "arktype/config" // use the "arktype/config" entrypoint configure({ numberAllowsNaN: true }) ``` ```ts title="app.ts" import "./config.ts" // import your config file before arktype import { type } from "arktype" type.number.allows(Number.NaN) // true ``` |
| **scope** | all Types parsed in the configured Scope | ```ts const myScope = scope( { User: { age: "number < 100" } }, { max: { actual: () => "unacceptably large" } } ) const types = myScope.export() // ArkErrors: age must be less than 100 (was unacceptably large) types.User({ name: "Alice", age: 101 }) const parsedAfter = myScope.type({ age: "number <= 100" }) // ArkErrors: age must be at most 100 (was unacceptably large) parsedAfter({ age: 101 }) ``` |
| **type** | all Types shallowly referenced by the configured Type | ```ts // avoid logging "was xxx" for password const Password = type("string >= 8").configure({ actual: () => "" }) const User = type({ email: "string.email", password: Password }) // ArkErrors: password must be at least length 8 const out = User({ email: "david@arktype.io", password: "ez123" }) ``` |
| optional | description | example |
|---|---|---|
| **description** | β a summary of the constraint that could complete the phrase "must be ___" π₯ reused by other metadata and should be your first go-to for customizing a message | ```ts const Password = type.string.atLeastLength(8).describe("a valid password") // ArkErrors: must be a valid password const out = Password("ez123") ``` |
| **expected** | β a function accepting the error context and returning a string of the format "must be ___" β specific to errors and takes precedence over `description` in those cases | ```ts const Password = type.string.atLeastLength(8).configure({ expected: ctx => ctx.code === "minLength" ? `${ctx.rule} characters or better` : "way better" }) // ArkErrors: must be 8 characters or better (was 5) const out1 = Password("ez123").toString() // ArkErrors: must be way better (was a number) const out2 = Password(12345678).toString() ``` |
| **actual** | β a function accepting the data that caused the error and returning a string of the format "(was ___)" β if an empty string is returned, the actual portion of the message will be omitted | ```ts const Password = type("string >= 8").configure({ actual: () => "" }) // ArkErrors: must be at least length 8 const out = Password("ez123") ``` |
| **problem** | β a function accepting the results of `expected` and `actual` in addition to other context and returning a complete description of the problem like "must be a string (was a number)" β may not apply to composite errors like unions | ```ts const Password = type("string >= 8").configure({ problem: ctx => `${ctx.actual} isn't ${ctx.expected}` }) // ArkErrors: 5 isn't at least length 8 const out1 = Password("ez123") // ArkErrors: a number isn't a string const out2 = Password(12345678) ``` |
| **message** | β a function accepting the result of `problem` in addition to other context and returning a complete description of the problem including the path at which it occurred β may not apply to composite errors like unions | ```ts const User = type({ password: "string >= 8" }).configure({ message: ctx => `${ctx.propString || "(root)"}: ${ctx.actual} isn't ${ctx.expected}` }) // ArkErrors: (root): a string isn't an object const out1 = User("ez123") // `.configure` only applies shallowly, so the nested error isn't changed! // ArkErrors: password must be at least length 8 (was 5) const out2 = User({ password: "ez123" }) ``` |
| kind | description | example |
|---|---|---|
| `domain` | One of 5 non-enumerable type sets (`string`, `number`, `object`, `bigint`, `symbol`) | `{ domain: "string" }` |
| `proto` | A constructor checked by `instanceof` (implies domain `object`) | `{ proto: Date }` |
| `unit` | An exact value checked by `===` (can be intersected with any other constraint and reduced to itself or `never`) | `{ unit: true }` |
| kind | description | example |
|---|---|---|
| `alias` | Stores a cyclic reference to a node | `{ reference: "$name" }` |
| `union` | A set of allowed nodes | `{ branches: ["string", "Array"] }` |
| `morph` | One or more transformations applied to valid data | `{ in: "string", morphs: [(s) => s.trim()] }` |
| `intersection` | An intersection of constraints | `{ domain: "number", divisor: 5 }` |
| kind | impliedBasis | description | example |
|---|---|---|---|
| `divisor` | `number` | Multiple of the specified integer | `{ rule: 2 }` |
| `pattern` | `string` | Matched by a regex | `{ rule: "^[a-z]+$" }` |
| `min` | `number` | Numeric minimum (inclusive by default) | `{ rule: 0, exclusive: true }` |
| `max` | `number` | Numeric maximum (inclusive by default) | `{ rule: 100 }` |
| `minLength` | `string | Array` | Inclusive minimum length | `{ rule: 1 }` |
| `maxLength` | `string | Array` | Inclusive maximum length | `{ rule: 255 }` |
| `exactLength` | `string | Array` | Exact length | `{ rule: 10 }` |
| `after` | `Date` | Minimum Date (inclusive by default) | `{ rule: new Date("2000-01-01") }` |
| `before` | `Date` | Maximum Date (inclusive by default) | `{ rule: new Date() }` |
| `predicate` | `unknown` | Custom `narrow` function | `{ predicate: (n) => n % 2 === 1 }` |
| kind | description | example |
|---|---|---|
| `sequence` | Defines array patterns with tuples, rest elements, and variadic parts | `{ sequence: { prefix: ["string", "number"] } }` |
| `required` | Defines a required property in an object structure | `{ key: "id", value: "number" }` |
| `optional` | Defines an optional property in an object structure | `{ key: "name", value: "string" }` |
| `index` | Defines index signatures for objects ( `[key: string]: value`) | `{ key: "string", value: "boolean" }` |
| kind | description | example |
|---|---|---|
| `domain` | One of 5 non-enumerable type sets (`string`, `number`, `object`, `bigint`, `symbol`) | `{ domain: "string" }` |
| `proto` | A constructor checked by `instanceof` (implies domain `object`) | `{ proto: Date }` |
| `unit` | An exact value checked by `===` (can be intersected with any other constraint and reduced to itself or `never`) | `{ unit: true }` |
| kind | description | example |
|---|---|---|
| `alias` | Stores a cyclic reference to a node | `{ reference: "$name" }` |
| `union` | A set of allowed nodes | `{ branches: ["string", "Array"] }` |
| `morph` | One or more transformations applied to valid data | `{ in: "string", morphs: [(s) => s.trim()] }` |
| `intersection` | An intersection of constraints | `{ domain: "number", divisor: 5 }` |
| kind | impliedBasis | description | example |
|---|---|---|---|
| `divisor` | `number` | Multiple of the specified integer | `{ rule: 2 }` |
| `pattern` | `string` | Matched by a regex | `{ rule: "^[a-z]+$" }` |
| `min` | `number` | Numeric minimum (inclusive by default) | `{ rule: 0, exclusive: true }` |
| `max` | `number` | Numeric maximum (inclusive by default) | `{ rule: 100 }` |
| `minLength` | `string | Array` | Inclusive minimum length | `{ rule: 1 }` |
| `maxLength` | `string | Array` | Inclusive maximum length | `{ rule: 255 }` |
| `exactLength` | `string | Array` | Exact length | `{ rule: 10 }` |
| `after` | `Date` | Minimum Date (inclusive by default) | `{ rule: new Date("2000-01-01") }` |
| `before` | `Date` | Maximum Date (inclusive by default) | `{ rule: new Date() }` |
| `predicate` | `unknown` | Custom `narrow` function | `{ predicate: (n) => n % 2 === 1 }` |
| kind | description | example |
|---|---|---|
| `sequence` | Array/tuple shape | `{ prefix: ["string"], variadic: "number" }` |
| `required` | Required object property | `{ key: "id", value: "number" }` |
| `optional` | Optional object property | `{ key: "name", value: "string" }` |
| `index` | Properties allowed by `signature` must conform to `value` | `{ signature: "string", value: "boolean" }` |