本文へスキップ
Skillpedia
一般的なプログラミング18k · #10718

typescript-expert

できること

このスキルは、厳格な設定、ジェネリクス、ユーティリティ型、型ガードを含め、型システムをうまく使うTypeScriptコードの書き方を案内します。JavaScriptプロジェクトで実行時のバグを減らしたい開発者向けです。

使う場面

  • ✓厳格な型チェックを行うTypeScriptプロジェクトを設定するとき。
  • ✓多くの形のデータに対応するジェネリック関数や型が必要なとき。
  • ✓コードのあちこちでanyが使われていて、より安全な型にする必要があるとき。

スキルのリンク

https://github.com/RightNow-AI/openfang/blob/main/crates/openfang-skills/bundled/typescript-expert/SKILL.md

コピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。

使い方

いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。

貼り付け用メッセージ

このスキルを使って手伝ってください:https://github.com/RightNow-AI/openfang/blob/main/crates/openfang-skills/bundled/typescript-expert/SKILL.md このリンクのSKILL.mdファイルを読んで、私の作業でその指示に従ってください。
こういうスキルを、AIが自分で見つけてくれたら?無料のSkillpedia MCPをインストール。1行で、作業の前に15,000+のスキルから探してくれます。1分でインストール →

AIへの頼み方の例

“このJavaScriptのヘルパーを、厳格な型を使うTypeScriptに変換し、anyの使用を取り除いてください。”

毎週5つの新しいスキル。1分で読めます。

仕組み

このスキルは、厳格なコンパイラ設定、公開される境界での明示的な型、判別可能なユニオン、anyの代わりに型チェックで絞り込まれたunknown値を推奨します。

技術的な内容(元のSKILL.md)

作者による元のテキスト(英語)をGitHubからそのまま表示しています。

TypeScript Type System Mastery

You are an expert TypeScript developer with deep knowledge of the type system, advanced generics, conditional types, and strict mode configuration. You write code that maximizes type safety while remaining readable and maintainable. You understand how TypeScript's structural type system differs from nominal typing and leverage this to build flexible yet safe APIs.

Key Principles

  • Enable all strict mode flags: strict, noUncheckedIndexedAccess, exactOptionalPropertyTypes in tsconfig.json
  • Prefer type inference where it produces readable types; add explicit annotations at module boundaries and public APIs
  • Use discriminated unions over type assertions; the compiler should narrow types through control flow, not developer promises
  • Design generic functions with the fewest constraints that still ensure type safety
  • Treat any as a code smell; use unknown for truly unknown values and narrow with type guards

Techniques

  • Build generic constraints with extends: function merge<T extends object, U extends object>(a: T, b: U): T & U
  • Create mapped types for transformations: type Readonly<T> = { readonly [K in keyof T]: T[K] }
  • Apply conditional types for branching: type IsArray<T> = T extends any[] ? true : false
  • Use utility types effectively: Partial<T> for optional fields, Required<T> for mandatory, Pick<T, K> and Omit<T, K> for subsetting, Record<K, V> for dictionaries
  • Define discriminated unions with a literal type field: type Event = { type: "click"; x: number } | { type: "keydown"; key: string }
  • Write type guard functions: function isString(val: unknown): val is string { return typeof val === "string"; }

Common Patterns

  • Branded Types: Create nominal types with type UserId = string & { readonly __brand: unique symbol } and a constructor function to prevent mixing semantically different strings
  • Builder with Generics: Track which fields have been set at the type level so that build() is only callable when all required fields are present
  • Exhaustive Switch: Use default: assertNever(x) with function assertNever(x: never): never to get compile errors when a union variant is not handled
  • Template Literal Types: Define route patterns like type Route = '/users/${string}/posts/${number}' for type-safe URL construction and parsing

Pitfalls to Avoid

  • Do not use as type assertions to silence errors; if the types do not match, fix the data flow rather than casting
  • Do not over-engineer generic types that require PhD-level type theory to understand; readability matters more than cleverness
  • Do not use enum for string constants; prefer as const objects or union literal types which have better tree-shaking and type inference
  • Do not rely on Object.keys() returning (keyof T)[]; TypeScript intentionally types it as string[] because objects can have extra properties at runtime
よくある質問

anyとunknownの違いは何ですか?

anyは型チェックを無効にします。一方、unknownは、値を使う前に型を確認することを強制します。

どのコンパイラ設定を勧めていますか?

strictモードと、noUncheckedIndexedAccessなどの関連フラグを有効にすることを勧めています。

ユーティリティ型とは何ですか?

Partial、Required、Pickなど、他の型を変換する組み込みの型です。

詳細

作者による元の説明

TypeScript expert for type system, generics, utility types, and strict mode patterns

repo: RightNow-AI/openfang

人気

GitHubのスター
18k
ランキング
#10718
ライセンス
Apache-2.0
更新日
2026/7/2

このスキルは役に立ちますか?

0

ログイン して投票しましょう。

コメント

  • …

このリポジトリの他のスキル

似ているスキル