jpskill.com
💬 コミュニケーション コミュニティ 🔴 エンジニア向け 👤 エンジニア・AI開発者

💬 Typescript

typescript

TypeScriptコードの書き方や編集時に、

⏱ 社内アナウンス文 30分 → 3分

📺 まず動画で見る(YouTube)

▶ 【最新版】Claude(クロード)完全解説!20以上の便利機能をこの動画1本で全て解説 ↗

※ jpskill.com 編集部が参考用に選んだ動画です。動画の内容と Skill の挙動は厳密には一致しないことがあります。

📜 元の英語説明(参考)

TypeScript code style and type-safety guide for LobeHub. Read before writing or editing any `.ts` / `.tsx` / `.mts` — covers `interface` vs `type`, `Record<PropertyKey, unknown>` over `any`/`object`, `as const satisfies`, `@ts-expect-error` over `@ts-ignore`, `import type` (`separate-type-imports`), `async`/`await` + `Promise.all`, `for…of` over indexed `for`, and the no-silent-`.catch(() => fallback)` rule. Also use when reviewing type quality, deciding module augmentation (`declare module`) over `namespace`, or designing extensible types (e.g. `PipelineContext.metadata`). Triggers on any TypeScript file edit, 'fix the type', 'why is this `any`', 'should this be interface or type', 'eslint type-import', 'ts-expect-error'.

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

一言でいうと

TypeScriptコードの書き方や編集時に、

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

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

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

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

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

💾 手動でダウンロードしたい(コマンドが難しい人向け)
  1. 1. 下の青いボタンを押して typescript.zip をダウンロード
  2. 2. ZIPファイルをダブルクリックで解凍 → typescript フォルダができる
  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-17
取得日時
2026-05-17
同梱ファイル
1

💬 こう話しかけるだけ — サンプルプロンプト

  • Typescript を使って、最小構成のサンプルコードを示して
  • Typescript の主な使い方と注意点を教えて
  • Typescript を既存プロジェクトに組み込む方法を教えて

これをClaude Code に貼るだけで、このSkillが自動発動します。

📖 Skill本文(日本語訳)

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

TypeScript コードスタイルガイド

型と型安全性

  • TypeScript が推論できる場合は、明示的な型アノテーションを避けてください。
  • 暗黙的な any を避けてください。必要な場合は明示的に型を指定してください。
  • 正確な型を使用してください。objectany よりも Record<PropertyKey, unknown> を優先してください。
  • オブジェクトの形状(例:React の props)には interface を優先し、ユニオン/インターセクションには type を使用してください。
  • 単純な as const よりも as const satisfies XyzInterface を優先してください。
  • as any よりも @ts-ignore よりも @ts-expect-error を優先してください。
  • 意味のない null/undefined パラメータを避け、厳密な関数契約を設計してください。
  • namespace よりも ES モジュール拡張 (declare module '...') を優先してください。namespace ベースの拡張パターンを導入しないでください。
  • 型に拡張性が必要な場合は、ソース型で小さなマージ可能なインターフェースを公開し、すべての拡張フィールドを1つのレジストリファイルに集中させるのではなく、各機能/プラグインがそれをローカルで拡張できるようにしてください。
  • PipelineContext.metadata のようなパッケージローカルな拡張性パターンについては、メタデータフィールドを、それらを読み書きするプロセッサ/プロバイダ/プラグインの隣で定義してください。

非同期パターン

  • コールバックや .then() チェーンよりも async/await を優先してください。
  • 同期 API(*Sync)よりも非同期 API を優先してください。
  • Promise ベースのバリアントを使用してください: import { readFile } from 'fs/promises'
  • 安全な並行処理には Promise.allPromise.race を使用してください。

インポート

  • このプロジェクトでは simple-import-sort/importsconsistent-type-imports (fixStyle: 'separate-type-imports') を使用しています。

  • 型インポートの分離: 型のみのインポートには、常に import type { ... } を使用し、インライン構文の import { type ... } は使用しないでください。

  • ファイルにすでにパッケージからの import type { ... } があり、値のインポートを追加する必要がある場合は、それらを2つの別々のステートメントとして保持してください。

    import type { ChatTopicBotContext } from '@lobechat/types';
    import { RequestTrigger } from '@lobechat/types';
  • 各インポートステートメント内では、指定子は名前でアルファベット順にソートされます。

コード構造

  • オブジェクトの分割代入を優先してください。
  • 一貫性のある記述的な命名を使用し、不明瞭な略語を避けてください。
  • マジックナンバー/文字列を適切に命名された定数に置き換えてください。
  • フォーマットはツールに任せてください。
  • export default よりも名前付きエクスポートを優先してください。これにより、リファクタリングによる名前変更と IDE の自動インポートが同期され、import Foo from './foo' で発生する default の名前変更のずれが回避されます。export default は、フレームワークがそれを要求するファイル(Next.js のページ/ルート/レイアウト、React.lazy のターゲット、vitest.config.ts のような設定ファイル)のために予約してください。

UI とテーマ

  • 生の HTML タグの代わりに @lobehub/ui、Ant Design コンポーネントを使用してください。
  • ダークモードとモバイルレスポンシブに対応したデザインにしてください。
  • ハードコードされた色の代わりに antd-style トークンシステムを使用してください。

パフォーマンス

  • packages/utils またはインストール済みの npm パッケージ内の既存のユーティリティを再利用してください。
  • データベースから必要な列のみをクエリしてください。

時間の一貫性

  • Date.now() を一度定数に割り当て、一貫性のために再利用してください。

ロギング

  • ユーザーの個人情報(API キーなど)は絶対にログに記録しないでください。
  • import { log } from 'debug' を直接使用しないでください(コンソールにログが出力されます)。
  • catch ブロックでは debug パッケージの代わりに console.error を使用してください。
  • .catch() コールバックでは常にエラーをログに記録してください。サイレントな .catch(() => fallback) は失敗を飲み込み、デバッグを不可能にします。
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開

TypeScript Code Style Guide

Types and Type Safety

  • Avoid explicit type annotations when TypeScript can infer
  • Avoid implicitly any; explicitly type when necessary
  • Use accurate types: prefer Record<PropertyKey, unknown> over object or any
  • Prefer interface for object shapes (e.g., React props); use type for unions/intersections
  • Prefer as const satisfies XyzInterface over plain as const
  • Prefer @ts-expect-error over @ts-ignore over as any
  • Avoid meaningless null/undefined parameters; design strict function contracts
  • Prefer ES module augmentation (declare module '...') over namespace; do not introduce namespace-based extension patterns
  • When a type needs extensibility, expose a small mergeable interface at the source type and let each feature/plugin augment it locally instead of centralizing all extension fields in one registry file
  • For package-local extensibility patterns like PipelineContext.metadata, define the metadata fields next to the processor/provider/plugin that reads or writes them

Async Patterns

  • Prefer async/await over callbacks or .then() chains
  • Prefer async APIs over sync ones (avoid *Sync)
  • Use promise-based variants: import { readFile } from 'fs/promises'
  • Use Promise.all, Promise.race for concurrent operations where safe

Imports

  • This project uses simple-import-sort/imports and consistent-type-imports (fixStyle: 'separate-type-imports')

  • Separate type imports: always use import type { ... } for type-only imports, NOT import { type ... } inline syntax

  • When a file already has import type { ... } from a package and you need to add a value import, keep them as two separate statements:

    import type { ChatTopicBotContext } from '@lobechat/types';
    import { RequestTrigger } from '@lobechat/types';
  • Within each import statement, specifiers are sorted alphabetically by name

Code Structure

  • Prefer object destructuring
  • Use consistent, descriptive naming; avoid obscure abbreviations
  • Replace magic numbers/strings with well-named constants
  • Defer formatting to tooling
  • Prefer named exports over export default — keeps refactor renames and IDE auto-import in sync, and avoids the default re-naming drift you get with import Foo from './foo'. Reserve export default for files where the framework requires it (Next.js page/route/layout, React.lazy targets, config files like vitest.config.ts)

UI and Theming

  • Use @lobehub/ui, Ant Design components instead of raw HTML tags
  • Design for dark mode and mobile responsiveness
  • Use antd-style token system instead of hard-coded colors

Performance

  • Reuse existing utils in packages/utils or installed npm packages
  • Query only required columns from database

Time Consistency

  • Assign Date.now() to a constant once and reuse for consistency

Logging

  • Never log user private information (API keys, etc.)
  • Don't use import { log } from 'debug' directly (logs to console)
  • Use console.error in catch blocks instead of debug package
  • Always log the error in .catch() callbacks — silent .catch(() => fallback) swallows failures and makes debugging impossible