ArkType
TypeScript's 1:1 validator, optimized from editor to runtime
typescript@4.9.5
in VS Code— no extensions or plugins required (how?)- node
- bun
- deno
- npm
- pnpm
- yarn
npm install arktype
pnpm add arktype
yarn add arktype
bun install arktype
import { type } from "npm:arktype"
ArkType is a runtime validation library that can infer TypeScript definitions 1:1 and reuse them as highly-optimized validators for your data.
With each character you type, you'll get immediate feedback from your editor in the form of either a fully-inferred Type
or a specific and helpful ParseError
.
This result exactly mirrors what you can expect to happen at runtime down to the punctuation of the error message- no plugins required.
Isomorphic
Define types using TS syntax. Infer them 1:1. Use them to validate your data at runtime.
const user = type({
name: "string",
device: {
platform: "'android'|'ios'",
"version?": "number"
}
})
// Hover to infer...
type User = typeof user.infer

Concise
Say more with less
// Hover to infer...
const arkUser = type({
name: /^ark.*$/ as Infer<`ark${string}`>,
birthday: morph("string", (s) => new Date(s)),
"powerLevel?": "1<=number<9000"
})

// Hover to infer...
const zodUser = z.object({
name: z.custom<`zod${string}`>(
(val) => typeof val === "string" && /^zod.*$/.test(val)
),
birthday: z.preprocess(
(arg) => (typeof arg === "string" ? new Date(arg) : undefined),
z.date()
),
powerLevel: z.number().gte(1).lt(9000).optional()
})

Optimized
ArkType is not just a validator— it's a full type system. Operations are deeply computed and optimized by default
// Hover to see internal representation...
export const deepLeftOrRight = union(
{
auto: {
discriminated: "'left'"
}
},
{
auto: {
discriminated: "'right'"
}
}
)

// Hover to see internal representation...
export const numericIntersection = type(
"(1 <= number%2 < 100) & (0 < number%3 <= 99)"
)

Type-safe
String definitions are statically parsed with each character you type and give detailed feedback just like in your editor.