jpskill.com
🛠️ 開発・MCP コミュニティ

arktype

TypeScriptの型定義を使って、実行時にデータの型を安全に検証できるArkTypeは、Zodの代替として、より高速な検証ライブラリを求める際に、型定義、検証、変換、スコープなどを活用し、TypeScriptの構文でデータを検証するSkill。

📜 元の英語説明(参考)

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.

🇯🇵 日本人クリエイター向け解説

一言でいうと

TypeScriptの型定義を使って、実行時にデータの型を安全に検証できるArkTypeは、Zodの代替として、より高速な検証ライブラリを求める際に、型定義、検証、変換、スコープなどを活用し、TypeScriptの構文でデータを検証するSkill。

※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。

⚡ おすすめ: コマンド1行でインストール(60秒)

下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。

🍎 Mac / 🐧 Linux
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o arktype.zip https://jpskill.com/download/14651.zip && unzip -o arktype.zip && rm arktype.zip
🪟 Windows (PowerShell)
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/14651.zip -OutFile "$d\arktype.zip"; Expand-Archive "$d\arktype.zip" -DestinationPath $d -Force; ri "$d\arktype.zip"

完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。

💾 手動でダウンロードしたい(コマンドが難しい人向け)
  1. 1. 下の青いボタンを押して arktype.zip をダウンロード
  2. 2. ZIPファイルをダブルクリックで解凍 → arktype フォルダができる
  3. 3. そのフォルダを C:\Users\あなたの名前\.claude\skills\(Win)または ~/.claude/skills/(Mac)へ移動
  4. 4. Claude Code を再起動

⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。

🎯 このSkillでできること

下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。

📦 インストール方法 (3ステップ)

  1. 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
  2. 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
  3. 3. 展開してできたフォルダを、ホームフォルダの .claude/skills/ に置く
    • · macOS / Linux: ~/.claude/skills/
    • · Windows: %USERPROFILE%\.claude\skills\

Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。

詳しい使い方ガイドを見る →
最終更新
2026-05-18
取得日時
2026-05-18
同梱ファイル
1

📖 Skill本文(日本語訳)

※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。

ArkType

概要

ArkType は、TypeScript 自身の型定義構文を使用するランタイム検証ライブラリです。新しい API (z.string().email()) を学習する代わりに、すでに知っている方法 ("string.email") で型を記述します。これは最速の TypeScript バリデーターであり、複雑なスキーマの場合、Zod より 100 倍高速で、より優れたエラーメッセージと、型とバリデーター間の 1 対 1 の対応関係があります。

使用場面

  • パフォーマンスが重要なランタイム検証 (ホットパス、大規模ペイロード)
  • TypeScript 構文 (ビルダー API ではない) を使用してバリデーターを記述したい場合
  • 詳細で人間が判読可能なエラーメッセージが必要な場合
  • パフォーマンスが重要なアプリケーションで Zod を置き換える場合
  • 型安全なデータ変換 (morphs)

手順

セットアップ

npm install arktype

基本型

// types.ts — TypeScript 構文を使用して型を定義する
import { type } from "arktype";

// 制約付きの文字列
const email = type("string.email");
const result = email("user@example.com");  // "user@example.com"
const error = email("not-an-email");       // ArkErrors: 有効なメールアドレスである必要があります

// オブジェクト型 — TypeScript のように見える
const User = type({
  name: "string >= 2",            // 最小長 2 の文字列
  email: "string.email",
  age: "number.integer >= 13",    // 整数、最小 13
  role: "'admin' | 'user'",       // リテラルユニオン
  "bio?": "string <= 500",        // オプション、最大 500 文字
});

// TypeScript の型を推論する — 個別のインターフェースは不要
type User = typeof User.infer;
// { name: string; email: string; age: number; role: "admin" | "user"; bio?: string }

// 検証
const valid = User({
  name: "Kai",
  email: "kai@example.com",
  age: 25,
  role: "user",
});

if (valid instanceof type.errors) {
  console.log(valid.summary);  // 人間が判読可能なエラーメッセージ
} else {
  console.log(valid.name);     // User として型付けされる
}

配列とネストされた型

// complex.ts — 複雑なネストされた型
import { type } from "arktype";

const Address = type({
  street: "string",
  city: "string",
  zip: "string.numeric",      // 数値文字列
  country: "string == 2",     // ちょうど 2 文字 (ISO コード)
});

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 (変換)

// morphs.ts — 検証中にデータを変換する
import { type } from "arktype";

// 文字列を数値に解析する
const numericString = type("string.numeric").pipe((s) => Number(s));
numericString("42");  // 42 (数値)

// API 入力を解析および変換する
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(",")), // "a,b,c" → ["a","b","c"]
});

スコープ (再利用可能な型システム)

// scope.ts — 相互接続された型を定義する
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);

例 1: API リクエストボディを検証する

ユーザープロンプト: "明確なエラーメッセージで、Express API での受信 POST リクエストを検証します。"

エージェントは、各エンドポイントのボディに対して ArkType スキーマを定義し、検証ミドルウェアを作成し、構造化されたエラー応答を返します。

例 2: Zod を ArkType に置き換える

ユーザープロンプト: "大規模なペイロードで Zod の検証が遅いです。より高速なものに切り替えてください。"

エージェントは、Zod スキーマを ArkType 構文に変換し、検証ミドルウェアを更新し、改善点をベンチマークします。

ガイドライン

  • TypeScript 構文z.string().email() ではなく "string.email"
  • エラーチェック用の type.errorsresult instanceof type.errors
  • TypeScript 型用の .infer — 重複するインターフェース定義は不要
  • 変換用の Morphs — 検証中に変換するには .pipe()
  • 複雑なスキーマ用のスコープ — 前方参照を使用して相互接続された型を定義する
  • Zod より 100 倍高速 — ホットパスと大規模なペイロードで重要
  • エラーメッセージは人間が判読可能 — 表示用の result.summary
  • オプション用の ? サフィックス"bio?": "string" は bio をオプションにする
  • 型内の制約"number >= 0 < 100" は範囲
  • Zod ほど実績がない — 新しいライブラリ、より小さなエコシステム
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開

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

// types.ts — Define types using TypeScript syntax
import { type } from "arktype";

// String with constraints
const email = type("string.email");
const result = email("user@example.com");  // "user@example.com"
const error = email("not-an-email");       // ArkErrors: must be an email address

// Object types — looks like TypeScript
const User = type({
  name: "string >= 2",            // String with min length 2
  email: "string.email",
  age: "number.integer >= 13",    // Integer, min 13
  role: "'admin' | 'user'",       // Literal union
  "bio?": "string <= 500",        // Optional, max 500 chars
});

// Infer the TypeScript type — no separate interface needed
type User = typeof User.infer;
// { name: string; email: string; age: number; role: "admin" | "user"; bio?: string }

// Validate
const valid = User({
  name: "Kai",
  email: "kai@example.com",
  age: 25,
  role: "user",
});

if (valid instanceof type.errors) {
  console.log(valid.summary);  // Human-readable error message
} else {
  console.log(valid.name);     // Typed as User
}

Arrays and Nested Types

// complex.ts — Complex nested types
import { type } from "arktype";

const Address = type({
  street: "string",
  city: "string",
  zip: "string.numeric",      // Numeric string
  country: "string == 2",     // Exactly 2 characters (ISO code)
});

const Order = type({
  id: "string.uuid",
  items: type({
    productId: "string",
    quantity: "number.integer > 0",
    price: "number > 0",
  }).array(),                   // Array of items
  shippingAddress: Address,
  total: "number > 0",
  status: "'pending' | 'shipped' | 'delivered'",
  createdAt: "Date",
});

type Order = typeof Order.infer;

Morphs (Transforms)

// morphs.ts — Transform data during validation
import { type } from "arktype";

// Parse string to number
const numericString = type("string.numeric").pipe((s) => Number(s));
numericString("42");  // 42 (number)

// Parse and transform API input
const CreateUserInput = type({
  name: "string.trim",                          // Auto-trim
  email: type("string.email").pipe((e) => e.toLowerCase()),  // Lowercase
  age: type("string.numeric").pipe(Number),     // String → number
  tags: type("string").pipe((s) => s.split(",")), // "a,b,c" → ["a","b","c"]
});

Scopes (Reusable Type Systems)

// scope.ts — Define interconnected types
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",            // Recursive reference
    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 checkingresult 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-readableresult.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