agentleFS
fideguchfideguch/my_pm_tools/skills/typescript-best-practices/SKILL.md

typescript-best-practices

Skill1 starsChanged 8 months agoMITView on GitHub

TypeScript プロジェクトの初期設定と型安全なコーディングのベストプラクティスを提供するスキル。 tsconfig.json の最適設定、パス エイリアス、厳格モードの段階的導入をガイドする。 React (Vite):

  • Installs packages

77 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use setup-pstack, poteto-help and 10 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • bnemaSkill

    setup-pstack

    Configure which Pi models pstack uses per role. Detects available provider/model specs and writes pstack's user configuration. Use for /setup-pstack, "configure pstack models", or changing pstack model choices.

    Also in 22 projects that use this

  • ianclearySkill

    poteto-help

    Guides users through pstack setup, /poteto-mode, and picking the skill, playbook, or principle for a task. Type /poteto-help with a question.

    Also in 12 projects that use this

  • eryzerzSkill

    make-bot-ui

    Use when building a custom UI (page, dashboard, buttons) that should wake a Grok Bot over a webhook, when the user must provide a webhook sender key, or when exposing that UI on Tailscale.

    Also in 14 projects that use this

  • ianclearySkill

    principle-explain-the-number

    Apply before you trust, report, or act on a number you measured: a speedup, a regression, a throughput, a latency, or an eval result. Find what limits it, and rule out that it measured something other than the work you think.

    Also in 20 projects that use this

  • tristanphvnSkill

    ketchup-video

    Catch the user up like /keel:ketchup, with a short silent video of slides for what happened and the waiting calls as text under it. Use for /keel:ketchup-video.

    Also in 8 projects that use this

  • instructureSkill

    ketchup

    Rebuild context after /clear by analyzing uncommitted changes across Canvas LMS and all plugin repositories

    Also in 17 projects that use this

The file

Files
SKILL.md

TypeScript ベストプラクティス & プロジェクト初期設定スキル

メタデータ

  • トリガー: 「TypeScript設定」「tsconfig設定」「TypeScriptプロジェクト初期設定」「型安全」
  • 前提条件: Node.js プロジェクト

概要

TypeScript プロジェクトの初期設定と型安全なコーディングのベストプラクティスを提供するスキル。 tsconfig.json の最適設定、パス エイリアス、厳格モードの段階的導入をガイドする。


Phase 1: TypeScript 導入判定

1.1 新規プロジェクト

npm install --save-dev typescript @types/node
npx tsc --init

1.2 既存 JavaScript プロジェクトの移行

npm install --save-dev typescript @types/node
# allowJs: true で段階的に移行

Phase 2: tsconfig.json 推奨設定

2.1 厳格モード(推奨)

{
  "compilerOptions": {
    "target": "ES2022",
    "module": "ESNext",
    "moduleResolution": "bundler",
    "lib": ["ES2022", "DOM", "DOM.Iterable"],

    "strict": true,
    "noUncheckedIndexedAccess": true,
    "noImplicitOverride": true,
    "noPropertyAccessFromIndexSignature": true,
    "exactOptionalPropertyTypes": false,

    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "skipLibCheck": true,
    "isolatedModules": true,
    "resolveJsonModule": true,
    "declaration": true,
    "declarationMap": true,
    "sourceMap": true,

    "outDir": "./dist",
    "rootDir": "./src",
    "baseUrl": ".",
    "paths": {
      "@/*": ["./src/*"]
    }
  },
  "include": ["src/**/*"],
  "exclude": ["node_modules", "dist", "coverage", "**/*.test.ts"]
}

2.2 フレームワーク別追加設定

Next.js:

{
  "compilerOptions": {
    "jsx": "preserve",
    "incremental": true,
    "plugins": [{ "name": "next" }]
  }
}

React (Vite):

{
  "compilerOptions": {
    "jsx": "react-jsx",
    "moduleResolution": "bundler"
  }
}

Phase 3: 型安全コーディングガイドライン

3.1 避けるべきパターン

// BAD: any の使用
function process(data: any) { ... }

// GOOD: 適切な型定義
interface ProcessInput {
  id: string;
  value: number;
}
function process(data: ProcessInput) { ... }

// BAD: 型アサーション の乱用
const user = response as User;

// GOOD: 型ガードの使用
function isUser(obj: unknown): obj is User {
  return typeof obj === 'object' && obj !== null && 'id' in obj;
}
if (isUser(response)) { ... }

// BAD: Non-null assertion の乱用
const name = user!.name;

// GOOD: オプショナルチェーン + nullish coalescing
const name = user?.name ?? 'Unknown';

3.2 推奨パターン

// Branded Types で型安全な ID
type UserId = string & { readonly __brand: 'UserId' };
type OrderId = string & { readonly __brand: 'OrderId' };

function createUserId(id: string): UserId {
  return id as UserId;
}

// Discriminated Union で安全な状態管理
type Result<T, E = Error> = { success: true; data: T } | { success: false; error: E };

// Exhaustive check
function assertNever(x: never): never {
  throw new Error(`Unexpected value: ${x}`);
}

// Readonly で不変性を保証
interface Config {
  readonly apiUrl: string;
  readonly timeout: number;
}

3.3 ユーティリティ型の活用

// Partial — 全プロパティをオプショナルに
type UpdateUser = Partial<User>;

// Pick / Omit — 必要なプロパティだけ抽出
type UserSummary = Pick<User, 'id' | 'name'>;
type UserWithoutPassword = Omit<User, 'password'>;

// Record — キー・値の型を指定
type StatusMap = Record<string, boolean>;

// Extract / Exclude — Union 型の操作
type NumericStatus = Extract<Status, number>;

Phase 4: テスト設定

4.1 Vitest(推奨)

npm install --save-dev vitest @vitest/coverage-v8
// vitest.config.ts
import { defineConfig } from 'vitest/config';
import path from 'path';

export default defineConfig({
  test: {
    globals: true,
    environment: 'node',
    coverage: {
      provider: 'v8',
      reporter: ['text', 'lcov'],
      exclude: ['node_modules/', 'dist/', '**/*.config.*'],
    },
  },
  resolve: {
    alias: {
      '@': path.resolve(__dirname, './src'),
    },
  },
});

4.2 package.json scripts

{
  "scripts": {
    "test": "vitest run",
    "test:watch": "vitest",
    "test:coverage": "vitest run --coverage"
  }
}

完了チェックリスト

#確認項目状態
1TypeScript がインストールされている
2tsconfig.json が strict: true で設定されている
3パスエイリアス (@/*) が設定されている
4npm run typecheck が正常動作する
5テストフレームワークが設定されている
6any の使用が最小限に抑えられている

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.