typescript-best-practices について
TypeScriptの実装とコードレビューに型システムの原則を適用するスキルです。不正な状態を表現しにくくし、外部データを型付きの境界で扱うことを重視します。
主な機能
- 01ブールフラグより判別可能なユニオンを優先
- 02設定リテラルの検査に `satisfies` を使用
- 03外部データを型付きの結果にパース
- 04意味の異なるプリミティブ型をブランド化
- 05危険な非 null アサーションを回避
- 06失敗しうる関数に結果ユニオンを使用
活用シーン
- 01TypeScriptの差分にある型のリスクをレビュー
- 02外部JSONやCLI入力を安全にモデル化
- 03オプショナル項目の曖昧さを避けた状態表現
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ yeachan-heo/ oh-my-claudecode --skill typescript-best-practicesインストール後、Claude Code で/typescript-best-practicesを入力して読み込まれたか確認します。
同梱ファイルreferences/patterns.md
README(原文)English
プロジェクトの README よりこの README の日本語訳はまだありません。以下は英語の原文です。日本語の紹介はページ上部をご覧ください。
TypeScript Best Practices
The type system is the cheapest place to make illegal states unrepresentable
(principles skill, Type system discipline). Concrete forms:
- Discriminated unions over boolean flags.
type Ev = {kind:'click'; x:number} | {kind:'focus'}— not{isClick:boolean; x?:number}. Exhaustiveswitchonkindturns missing cases into compile errors. satisfiesfor configuration literals.{...} satisfies Configkeeps literal inference while checking the shape.- Parse, don't validate, at boundaries. External data (JSON, env, CLI args, API responses) passes through one parsing function returning a typed result; downstream code takes the parsed type, never
anyre-cast.unknownin, typed out. - Brand primitives that carry meaning.
type SessionId = string & {__brand:'SessionId'}when mixing twostrings is a realistic bug. - No non-null assertions on external data.
!is allowed only where a check on a previous line proves the value; at boundaries it is a runtime crash with compile-time approval. - Return types that prevent misuse. A function that can fail returns a result union, not
Tplus a thrown maybe; callers must handle both arms to compile. readonlyby default on shared shapes, mutation as an explicit opt-in.
Reviewing
When reviewing TS, the question per diff hunk is not "does it compile" but
"which illegal state did this type just permit" — flag flags-over-unions,
boundary anys, and unbranded overlapping primitives.
Rules
- Discipline applies at the boundary and the domain model; inside a single function, pragmatism wins.
- Never introduce a type abstraction with one caller and no second one
coming (
minimal-code-discipline).
コメント
Markdown 対応