Skip to main content
The ArkType adapter enables type-safe search parameter validation using ArkType, a runtime validation library with TypeScript-like syntax.

Installation

Install both the ArkType adapter and ArkType itself:
ArkType requires version >=2.0.0-rc and <3

Basic Usage

Import the arkTypeValidator function and pass it an ArkType schema:
Now your search parameters are validated and typed:

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
Returns:
  • A ValidatorAdapter that can be used with validateSearch
Type Inference:
  • Input type: Inferred from schema['inferIn']
  • Output type: Inferred from schema['infer']

Comparison with Other Libraries

ArkType’s syntax is more concise and closely resembles TypeScript types.

Next Steps

Zod Adapter

Most popular validation library

Valibot Adapter

Lightweight modular validation