TypeScript type validation with ArkType, ArkEnv, and ArkRegex. Use for schemas, environment variables, and type-safe regex.
ArkType is a TypeScript-first validation library with powerful runtime type checking, scopes, generics, and pattern matching. Use this skill when defining schemas, validating data, or working with type-safe APIs.
Reference this skill when:
match| Syntax | Use Case | Example |
|--------|-----------|---------|
| String | Concise definitions | type({ name: "string", age: "number >= 18" }) |
| Fluent | Chaining methods | type.string.atLeastLength(8).email() |
| Tuple | Complex/nested | type(["string", ["number", "number"]]) |
| Args | Operators | type("string", "|", "boolean") |
| Method | Returns |
|--------|---------|
| .validate(data) | { data: T } | { errors: ArkErrors } |
| .assert(data) | Validated data or throws |
| Type as function | Validated data or type.errors instance |
| Operator | Meaning |
|----------|---------|
| | | Union |
| & | Intersection |
| > / >= | Greater than (exclusive/inclusive) |
| < / <= | Less than (exclusive/inclusive) |
| % | Divisible by |
| ? suffix | Optional property |
| = suffix | Default value |
String Syntax (Most Concise)
const User = type({
name: "string",
age: "number.integer >= 0",
email: "string.email",
"role?": "'admin' | 'user' = 'user'"
})
Fluent API (Best for chaining)
const Password = type.string
.atLeastLength(8)
.describe("a valid password")
Define a Scope
const types = scope({
Id: "string",
User: { id: "Id", name: "string" },
"User[]": "User[]"
}).export()
Basic Generic
const boxOf = type("<t>", { value: "t" })
const StringBox = boxOf({ type: "string" })
Constrained Generic
const nonEmpty = type("<arr extends unknown[]>", "arr > 0")
import { match } from "arktype"
const sizeOf = match({
string: v => v.length,
number: v => v,
default: "assert"
})
// Discriminated union matching
const getValue = match
.in<{ id: 1 } | { id: 2 }>()
.at("id")
.match({
1: o => o.value,
2: o => o.other,
default: "assert"
})
import { arkenv } from "arkenv"
const env = arkenv({
HOST: "string.host",
PORT: "number.port",
NODE_ENV: "'development' | 'production' | 'test' = 'development'"
})
// Fully typed - TypeScript knows exact types!
console.log(env.HOST) // string
console.log(env.PORT) // number
console.log(env.NODE_ENV) // "development" | "production" | "test"
ArkEnv Keywords
| Keyword | Validates |
|---------|----------|
| string.host | Hostname |
| string.url | URL |
| number.port | Port (1-65535) |
| string.email | Email format |
| string.uuid.v4 | UUID v4 |
import { regex } from "arkregex"
const ok = regex("^ok$", "i")
// Regex<"ok" | "oK" | "Ok" | "OK", { flags: "i" }>
const semver = regex("^(\\d*)\\.(\\d*)\\.(\\d*)$")
// Regex<`${bigint}.${bigint}.${bigint}`, { captures: [bigint, bigint, bigint] }
const email = regex("^(?<name>\\w+)@(?<domain>\\w+\\.\\w+)$")
// Regex with typed groups: { name: string; domain: `${string}.${string}` }
Features
| Feature | Description |
|---------|-------------|
| Type inference | Infers capture types from pattern |
| Named groups | .groups object is fully typed |
| Zero runtime | Uses native RegExp at runtime |
| TS 5.9+ | Required for best experience |
import { attest, setup } from "@ark/attest"
setup()
it("type tests", () => {
attest<string>(myType.infer)
attest(myType.json).snap({ /* ... */ })
})
// Type to JSON Schema
const schema = User.toJsonSchema()
// JSON Schema to Type
import { jsonSchemaToType } from "@ark/json-schema"
const T = jsonSchemaToType({ type: "string", minLength: 5 })
const Node = scope({
Node: {
value: "string",
"children?": "Node[]"
}
}).export().Node
const Event = type({
type: "'click'",
x: "number",
y: "number"
}).or({
type: "'keydown'",
key: "string"
})
const Even = type("number % 2").brand("even")
type Even = typeof Even.infer
type() for one-off, scope() for reusable.assert()instanceof type.errors.export() for public APIsgithub.com/arktypeio/arktypetypescript - TypeScript best practicesSearch for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer