Type API
Name | Summary | Notes & Examples |
---|---|---|
$ | Scope in which chained methods are parsed | |
infer | type of output this returns | 🥸 inference-only property that will be |
inferIn | type of input this allows | 🥸 inference-only property that will be |
json | internal JSON representation | |
toJsonSchema | generate a JSON Schema | |
meta | metadata like custom descriptions and error messages | |
description | human-readable English description | ✅ works best for primitive values |
expression | syntax string similar to native TypeScript | ✅ works well for both primitives and structures |
assert | validate and return transformed data or throw | |
allows | check input without applying morphs | ✅ good for stuff like filtering that doesn't benefit from detailed errors |
configure | add metadata to shallow references | ⚠️ does not affect error messages within properties of an object |
describe | add description to shallow references | ⚠️ does not affect error messages within properties of an object |
onUndeclaredKey | apply undeclared key behavior | • • • |
onDeepUndeclaredKey | deeply apply undeclared key behavior | • • • |
from | alias for assertwith typed input | |
as | cast the way this is inferred | 🥸 inference-only function that does nothing runtime |
brand | add a compile-time brand to output | 🥸 inference-only function that does nothing runtime |
and | intersect the parsed Type, throwing if the result is unsatisfiable | |
or | union with the parsed Type | ⚠️ a union that could apply different morphs to the same data is a ParseError ([docs](https://arktype.io/docs/expressions/union-morphs)) |
array | an array of this | |
optional | optional definition | ⚠️ unlike most other methods, this creates a definition rather than a Type (read why) |
default | defaultable definition | ✅ object defaults can be returned from a function ⚠️ throws if the default value is not allowed ⚠️ unlike most other methods, this creates a definition rather than a Type (read why) |
filter | apply a predicate function to input | ✅ most useful for morphs with input types that are re-used externally |
narrow | apply a predicate function to output | ✅ go-to fallback for validation not composable via built-in types and operators ✅ runs after all other validators and morphs, if present |
intersect | intersect the parsed Type, returning an introspectable Disjointif the result is unsatisfiable | |
equals | check if the parsed Type's constraints are identical | ✅ equal types have identical input and output constraints and transforms |
ifEquals | narrow this based on an equalscheck | |
extends | check if this is a subtype of the parsed Type | ✅ a subtype must include all constraints from the base type |
ifExtends | narrow this based on an extendscheck | |
overlaps | check if a value could satisfy this and the parsed Type | |
extract | extract branches extending the parsed Type | |
exclude | exclude branches extending the parsed Type |