| name | arktype |
| description | Define runtime-validated types with ArkType — TypeScript's 1:1 validator. Use when someone asks to "validate data in TypeScript", "runtime type checking", "ArkType", "type-safe validation", "alternative to Zod", "faster validation library", or "validate with TypeScript syntax". Covers type definitions, validation, morphs (transforms), scopes, and comparison with Zod. |
| license | Apache-2.0 |
| compatibility | TypeScript 5.1+. Node.js/Bun/Deno/browser. |
| metadata | {"author":"terminal-skills","version":"1.0.0","category":"development","tags":["validation","typescript","arktype","runtime-types","schema"]} |
ArkType
Overview
ArkType is a runtime validation library that uses TypeScript's own syntax for type definitions. Instead of learning a new API (z.string().email()), you write types the way you already know ("string.email"). It's the fastest TypeScript validator — 100x faster than Zod for complex schemas — with better error messages and 1:1 correspondence between your types and validators.
When to Use
- Runtime validation where performance matters (hot paths, large payloads)
- Want to write validators using TypeScript syntax (not a builder API)
- Need detailed, human-readable error messages
- Replacing Zod in performance-critical applications
- Type-safe data transformations (morphs)
Instructions
Setup
npm install arktype
Basic Types
import { type } from "arktype";
const email = type("string.email");
const result = email("user@example.com");
const error = email("not-an-email");
const User = type({
name: "string >= 2",
email: "string.email",
age: "number.integer >= 13",
role: "'admin' | 'user'",
"bio?": "string <= 500",
});
type User = typeof User.infer;
const valid = User({
name: "Kai",
email: ,
: ,
: ,
});
(valid .) {
.(valid.);
} {
.(valid.);
}
Arrays and Nested Types
import { type } from "arktype";
const Address = type({
street: "string",
city: "string",
zip: "string.numeric",
country: "string == 2",
});
const Order = type({
id: "string.uuid",
items: type({
productId: "string",
quantity: "number.integer > 0",
price: "number > 0",
}).array(),
shippingAddress: Address,
total: "number > 0",
status: "'pending' | 'shipped' | 'delivered'",
createdAt: "Date",
});
type Order = typeof Order.infer;
Morphs (Transforms)
import { type } from "arktype";
const numericString = type("string.numeric").pipe((s) => Number(s));
numericString("42");
const CreateUserInput = type({
name: "string.trim",
email: type("string.email").pipe((e) => e.toLowerCase()),
age: type("string.numeric").pipe(Number),
tags: type("string").pipe((s) => s.split(",")),
});
Scopes (Reusable Type Systems)
import { scope } from "arktype";
const types = scope({
user: {
id: "string.uuid",
name: "string >= 2",
email: "string.email",
posts: "post[]",
},
post: {
id: "string.uuid",
title: "string >= 1",
content: "string",
author: "user",
tags: "string[]",
},
}).export();
const user = types.user(data);
Examples
Example 1: Validate API request bodies
User prompt: "Validate incoming POST requests in my Express API with clear error messages."
The agent will define ArkType schemas for each endpoint's body, create validation middleware, and return structured error responses.
Example 2: Replace Zod with ArkType
User prompt: "My Zod validation is slow on large payloads. Switch to something faster."
The agent will translate Zod schemas to ArkType syntax, update validation middleware, and benchmark the improvement.
Guidelines
- TypeScript syntax —
"string.email" not z.string().email()
type.errors for error checking — result instanceof type.errors
.infer for TypeScript type — no duplicate interface definitions
- Morphs for transforms —
.pipe() to transform during validation
- Scopes for complex schemas — define interconnected types with forward references
- 100x faster than Zod — matters for hot paths and large payloads
- Error messages are human-readable —
result.summary for display
? suffix for optional — "bio?": "string" makes bio optional
- Constraints in the type —
"number >= 0 < 100" is a range
- Not as battle-tested as Zod — newer library, smaller ecosystem