一键导入
typescript-conventions
関数型プログラミングベースのTypeScriptコーディング規約。 TypeScriptコード(.ts/.tsx)の実装時に適用する。 型、アロー関数、Result型エラーハンドリング、不変性、命名、import、async、pipe/合成を規定。
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
関数型プログラミングベースのTypeScriptコーディング規約。 TypeScriptコード(.ts/.tsx)の実装時に適用する。 型、アロー関数、Result型エラーハンドリング、不変性、命名、import、async、pipe/合成を規定。
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Git コミットメッセージの規約。Conventional Commits 形式、日本語。 Apply when creating git commits, reviewing commit messages, or when the user asks to commit changes.
React / Next.js の TypeScript 規約。 コンポーネント(.tsx)、hooks、Server Components、Client Components、 Server Actions の実装時に適用する。
コミット前のセルフレビュー。プロジェクトの規約に沿っているかチェックする。 Apply when the user asks to review code, check conventions, or requests a self-review before committing.
スタイリング規約。Tailwind CSS v4 と inline styles の使い分け。 UI コンポーネントやプレビュー領域のスタイリング時に適用する。 Tailwind はアプリ UI に、inline styles はプレビュー領域に使い、混在させない。
TDD(テスト駆動開発)のワークフロー。 新機能やバグ修正の実装時に適用する。 Red → Green → Refactor のサイクルを必ず守る。
Vitest を使った TypeScript テスト規約。 テスト(.test.ts, .test.tsx)の作成・レビュー時に適用する。 純関数テスト、Result 型テスト、React コンポーネントテスト、モックを規定。
| name | typescript-conventions |
| description | 関数型プログラミングベースのTypeScriptコーディング規約。 TypeScriptコード(.ts/.tsx)の実装時に適用する。 型、アロー関数、Result型エラーハンドリング、不変性、命名、import、async、pipe/合成を規定。 |
neverthrow の Result で返す| スコープ | ルール |
|---|---|
| export / 公開 API | Readonly<>, readonly 配列, Result 戻り値, mutation 禁止 |
| モジュール内部 | Readonly 推奨、ローカル let は封じ込めれば可 |
| 関数ローカル | 外に漏れない一時的な mutation は許容 |
// interface ではなく type alias + Readonly
type User = Readonly<{
id: string
name: string
roles: readonly string[]
}>
// 型の導出
type UserInput = Omit<User, "id">
// ドメインプリミティブにはブランド型
type Email = string & { readonly __brand: "Email" }
// enum ではなくユニオン型
type Status = "active" | "inactive" | "pending"
// 設定オブジェクトには as const satisfies
const ROUTES = {
home: "/",
user: (id: string) => `/users/${id}`,
} as const satisfies Record<string, string | ((...args: never[]) => string)>
アロー関数を優先。function 宣言は非推奨。
export const formatName = (user: Readonly<{ first: string; last: string }>): string =>
`${user.first} ${user.last}`
// 引数3つ以上 → パラメータオブジェクト
type SearchParams = Readonly<{ query: string; limit: number; offset: number }>
export const search = (params: SearchParams): ResultAsync<readonly User[], AppError> => { ... }
import { ok, err, Result, ResultAsync } from "neverthrow"
// ドメインエラーは判別可能ユニオンで定義
type AppError =
| Readonly<{ code: "NOT_FOUND"; id: string }>
| Readonly<{ code: "VALIDATION"; message: string }>
// throw せず Result で返す
export const validateAge = (input: unknown): Result<number, AppError> => {
const age = Number(input)
return Number.isNaN(age) || age < 0
? err({ code: "VALIDATION", message: `Invalid age: ${input}` })
: ok(age)
}
// andThen / map でチェーン
export const createUser = (input: RawInput): ResultAsync<User, AppError> =>
validateInput(input).andThen(checkDuplicate).asyncAndThen(saveToDb)
// 配列操作 — 常に新しい配列を返す
const addItem = <T>(items: readonly T[], item: T): readonly T[] => [...items, item]
const updateAt = <T>(items: readonly T[], i: number, fn: (v: T) => T): readonly T[] =>
items.map((item, idx) => idx === i ? fn(item) : item)
// ローカルスコープの mutation は封じ込めれば OK
const buildLookup = (users: readonly User[]): ReadonlyMap<string, User> => {
const map = new Map<string, User>()
for (const u of users) map.set(u.id, u)
return map
}
// 並行
const result = await ResultAsync.combine([fetchUser(id), fetchOrders(id)])
result.map(([user, orders]) => ({ user, orders }))
// 逐次
const result = await validateInput(raw)
.asyncAndThen(findUser)
.andThen(checkPermission)
.asyncAndThen(execute)
const pipe = <T>(value: T, ...fns: readonly ((v: T) => T)[]): T =>
fns.reduce((acc, fn) => fn(acc), value)
const processName = (raw: string) =>
pipe(raw, (s) => s.trim(), (s) => s.toLowerCase(), (s) => s.replace(/\s+/g, "-"))
| 種類 | 規則 | 例 |
|---|---|---|
| ファイル | kebab-case | format-date.ts |
| 関数 / 変数 | camelCase | formatDate |
| 真偽値 | is/has/can 接頭辞 | isActive |
| ファクトリ | create 接頭辞 | createService |
| 定数 | UPPER_SNAKE_CASE | MAX_RETRY |
| 型 | PascalCase | UserProfile |
| イベントハンドラ | handle 接頭辞 | handleSubmit |
| コールバック props | on 接頭辞 | onSubmit |
external → @/ エイリアス → 相対パス → import type
import { z } from "zod"
import { ok, type Result } from "neverthrow"
import { parseWith } from "@/lib/zod-utils"
import { validate } from "./validate"
import type { User } from "./types"
function 宣言 → アロー関数を使うclass → plain object + functionsenum → ユニオン型any → unknown + 型の絞り込みinterface → type + Readonlythrow → Resultexport default → named export