Installation
Install both the ArkType adapter and ArkType itself:ArkType requires version
>=2.0.0-rc and <3Basic Usage
Import thearkTypeValidator function and pass it an ArkType schema:
Why ArkType?
ArkType stands out for its unique approach:- TypeScript-like syntax - Write schemas that look like TypeScript types
- Runtime and type-level - Single source of truth for types and validation
- Fast - Optimized for runtime performance
- Concise - Less boilerplate than other validation libraries
Type Syntax
ArkType uses intuitive string-based type definitions:Basic Types
Optional and Nullable
String Constraints
Number Constraints
Literals and Unions
Arrays
Nested Objects
Default Values
ArkType supports default values with the= operator:
Transformations
ArkType allows you to transform values during parsing:Type Safety
ArkType provides excellent type inference:Custom Validation
Create reusable type definitions:Validation Methods
ArkType schemas provide multiple validation methods:Error Handling
When validation fails, ArkType provides detailed error information:Real-World Example
Here’s a complete example with pagination, filtering, and sorting:Type Inference
Extract types from ArkType schemas:API Reference
arkTypeValidator(schema)
Creates a validator adapter from an ArkType schema.
Parameters:
schema- An ArkType type definition
- A
ValidatorAdapterthat can be used withvalidateSearch
- Input type: Inferred from
schema['inferIn'] - Output type: Inferred from
schema['infer']
Comparison with Other Libraries
Next Steps
Zod Adapter
Most popular validation library
Valibot Adapter
Lightweight modular validation