ArkType

Search for a command to run...

No comments yet. Be the first to comment.
Bun, the hyper-fast JavaScript runtime known for its incredible speed and Zig-based architecture, is being completely rewritten in Rust. For a project that has over 22 million monthly downloads and ea

Next.js 16.3 is almost here, and it's packed with a ton of improvements and let's see them in this post 1.Instant Navigation For a while now, there’s been a valid, lingering debateServer Components vs

It’s official. React has merged its long-awaited Rust port of the React Compiler (formerly known as React Forget) into the main repository. What started as an experimental research project by Joseph S

If you follow modern technology trends, you have likely been led to believe that artificial intelligence is entirely built on Python. Every tutorial, machine learning framework documentation, and open

Just when the JavaScript ecosystem was catching its breath after last week’s TanStack Router compromise, the Mini Shai-Hulud supply chain worm has continued its relentless march. Developed by the thre

ArkType is a TypeScript-first runtime type validation library. It allows you to define types and validation rules using TypeScript-like syntax, and then validate data at runtime while keeping full TypeScript type inference.
In simple terms
ArkType lets you define a type once, and use it for both compile-time typing and runtime validation
In TypeScript, types exist only during development (compile time). When your code runs, TypeScript types disappear.
type User = {
name: string
age: number
}
If you receive JSON from an API
const data = JSON.parse(input)
TypeScript cannot guarantee that data actually matches User.
This is where ArkType helps — it validates the data at runtime.
import { type } from "arktype"
const User = type({
name: "string",
age: "number"
})
const result = User({ name: "John", age: 30 })
if (result instanceof Error) {
console.log(result.message)
} else {
console.log("Valid user")
}
What happens in the above code
We define a schema
Pass data to it
ArkType validates it at runtime
TypeScript automatically knows the type.
const User = type({
id: "number",
email: "string.email",
age: "number >= 18"
})
User({
id: 1,
email: "test@mail.com",
age: 20
})
Invalid input throws structured errors.
type UserType = typeof User.infer
TypeScript automatically understands the type.
ArkType is designed to be extremely fast compared to many validation libraries like Zod, Yup. ArkType takes 14 nanoseconds at runtime which is 20x faster than Zod and 2000x faster than Yup.
You can check the benchmarks here: https://moltar.github.io/typescript-runtime-type-benchmarks/
| Library | Syntax | Speed | TypeScript Integration |
|---|---|---|---|
| ArkType | Very Simple | Very Fast | Excellent |
| Zod | Verbose | Medium | Good |
| Yup | Verbose | Slower | Limited |
| Joi | Complex | Medium | Weak |
ArkType
const User = type({
name: "string",
age: "number > 18"
})
// extract the type if needed
type User = typeof User.infer
Zod
const User = z.object({
name: z.string(),
age: z.number().min(18)
})
ArkType is much shorter and closer to natural TypeScript.
You can install arktype with the following command
bun install arktype
Ensure you have
TypeScript version >=5.1.
A package.json with "type": "module" (or an environment that supports ESM imports)
A tsconfig.json with...
strict or strictNullChecks (required)
skipLibCheck (recommended)
exactOptionalPropertyTypes (recommended)
VS Code Extension - To take advantage of all ArkType's autocomplete capabilities, you'll need to add the following to your workspace settings at ./vscode/settings.json
// allow autocomplete for ArkType expressions like "string | num"
"editor.quickSuggestions": {
"strings": "on"
},
// prioritize ArkType's "type" for autoimports
"typescript.preferences.autoImportSpecifierExcludeRegexes": [
"^(node:)?os$"
],
You can check more about ArkType from their official documentation: https://arktype.io/docs/intro/setup
Well you have gathered some information about ArkType today and just start building things with ArkType and see how it works for you.
Will catchup in another interesting post :)