ArkType 3.0: TypeScript-syntax validation with build-time precompilation and easy Zod migrationNote · digest for December 5
Studio composition of ArkType 3.0 validator precompilation: a large schema blueprint compresses during the build into a tiny, ultra-fast green microchip
Note3 sections≈ 5 min

ArkType 3.0: TypeScript-syntax validation with build-time precompilation and easy Zod migration

TypeScript types vanish after compilation, so data from APIs and forms still needs runtime checks. Usually you pick between familiar Zod with its bundle weight and alternatives like fast Typia (which needs a compiler step) or tiny Valibot.

ArkType 3.0 tries to combine both worlds. You write schemas almost like TypeScript types, and the @ark/aot plugin precompiles them into plain JS at build time.

TypeScript syntax instead of method chains

ArkType writes constraints as strings like "string > 0", "string.email", and "age?", while tsc catches typos right in your editor. Compare a signup schema:

// Zod 4
import { z } from "zod"
const Signup = z.object({
  email: z.email("Enter a valid email"),
  password: z.string().min(8, "Use 8+ chars"),
  role: z.enum(["admin", "member"])
})

// ArkType 3.0
import { type } from "arktype"
const SignupArk = type({
  email: type("string.email").message("Enter a valid email"),
  password: type.string.atLeastLength(8, "Use 8+ chars"),
  role: "'admin' | 'member'"
})
type SignupArk = typeof SignupArk.infer

It's shorter, and .message() formats errors without the field path, just like Zod. Watch out for one difference when porting z.object(): ArkType keeps extra keys and rejects undefined on optional fields. You can match Zod's defaults with one call to configure({ onUndeclaredKey: "delete", exactOptionalPropertyTypes: false }) from arktype/config.

Build-time precompilation: gains and costs

Before 3.0, ArkType compiled JIT functions at runtime. That kept the parser in your bundle, and strict CSPs without unsafe-eval (like Cloudflare Workers) blocked eval and new Function. In 3.0, the @ark/aot plugin works via @ark/aot/unplugin with Vite, webpack, Rollup, esbuild, and Bun (plus Turbopack and ark emit):

// vite.config.ts
import { precompile } from "@ark/aot/unplugin"
export default { plugins: [precompile.vite()] }

// Auto-discriminated union without manual tag config
const Shape = type({ kind: "'circle'", radius: "number > 0" })
  .or({ kind: "'square'", side: "number > 0" })

The compiler reduces schemas using set theory: it spots kind and emits switch (data?.kind), drops redundant ranges, and fails the build on contradictions. Only lightweight arktype/runtime ships to production, fully compatible with strict CSP.

ArkType's benchmarks show precompilation runs 15x faster than Zod 4 on average (5.3x faster than z.compile) and uses 23.8%+ fewer startup instructions. Bundle sizes diverge sharply:

Validator size on a login form (gzipped, esbuild)

The chart also shows the flip side: without the plugin, dynamic ArkType 3.0 nearly doubled in size compared to 2.2.9, so don't ship it uncompiled to the browser.

Build times have a cost too. Across 92 types, builds slow down by 1–2.5s; at 1,012 types, a cold Vite 8 build takes 7.3s instead of 414 ms (20.3s in Next 16). Past a thousand types, you need preset: "smallest" or the precompiled bundle grows as big as the dynamic one, and runtime-variable schemas still need runtime: "arktype".

Forms out of the box and migrating from Zod

Through Standard Schema, TanStack Form accepts ArkType schemas directly, and React Hook Form connects via standardSchemaResolver from @hookform/resolvers:

// TanStack Form: pass the schema directly
import { useForm } from "@tanstack/react-form"
import { type } from "arktype"

const User = type({
  name: type("string > 0").message("Name is required"),
  age: "number.integer >= 0"
})
export const useUserForm = () =>
  useForm({
    defaultValues: { name: "", age: 0 },
    validators: { onChange: User }
  })

// React Hook Form: via standardSchemaResolver
import {
  standardSchemaResolver
} from "@hookform/resolvers/standard-schema"
import { useForm as useRhf } from "react-hook-form"
export const useRhfUser = () =>
  useRhf({ resolver: standardSchemaResolver(User) })

You can migrate from Zod one file at a time because type({ ... }) lets you nest an existing Zod schema (that piece just skips precompilation). Tools like npx skills add arktypeio/arktype, npx arktype check, and test shadow mode help automate the move.

Leave working Zod alone if you rely heavily on async .refine() (ArkType is strictly sync), use packages like MCP SDK v1 that require Zod, or lack a build step. On Vite and Next.js apps with tight bundle budgets or strict CSPs without unsafe-eval, ArkType 3.0 with @ark/aot solves all three.

Want a deep diveVotes help us choose what to break down in detail. This material has 0 votes.
Sources · 8