💬 Typescript
TypeScriptコードの書き方や編集時に、
📺 まず動画で見る(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本体の挙動とは独立した参考情報です。
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
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
$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. 下の青いボタンを押して
typescript.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
typescriptフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-17
- 取得日時
- 2026-05-17
- 同梱ファイル
- 1
💬 こう話しかけるだけ — サンプルプロンプト
- › Typescript を使って、最小構成のサンプルコードを示して
- › Typescript の主な使い方と注意点を教えて
- › Typescript を既存プロジェクトに組み込む方法を教えて
これをClaude Code に貼るだけで、このSkillが自動発動します。
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
TypeScript コードスタイルガイド
型と型安全性
- TypeScript が推論できる場合は、明示的な型アノテーションを避けてください。
- 暗黙的な
anyを避けてください。必要な場合は明示的に型を指定してください。 - 正確な型を使用してください。
objectやanyよりも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.all、Promise.raceを使用してください。
インポート
-
このプロジェクトでは
simple-import-sort/importsとconsistent-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>overobjectorany - Prefer
interfacefor object shapes (e.g., React props); usetypefor unions/intersections - Prefer
as const satisfies XyzInterfaceover plainas const - Prefer
@ts-expect-errorover@ts-ignoreoveras any - Avoid meaningless null/undefined parameters; design strict function contracts
- Prefer ES module augmentation (
declare module '...') overnamespace; do not introducenamespace-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/awaitover 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.racefor concurrent operations where safe
Imports
-
This project uses
simple-import-sort/importsandconsistent-type-imports(fixStyle: 'separate-type-imports') -
Separate type imports: always use
import type { ... }for type-only imports, NOTimport { 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 thedefaultre-naming drift you get withimport Foo from './foo'. Reserveexport defaultfor files where the framework requires it (Next.js page/route/layout, React.lazy targets, config files likevitest.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-styletoken system instead of hard-coded colors
Performance
- Reuse existing utils in
packages/utilsor 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.errorin catch blocks instead of debug package - Always log the error in
.catch()callbacks — silent.catch(() => fallback)swallows failures and makes debugging impossible