typescript
БесплатноБез исполняемых скриптовНе проверенApply when writing TypeScript code. Strict types, discriminated unions, async patterns, and runtime safety.
Об этом скилле
Sub-Skill: TypeScript Best Practices
Purpose: Prevents the TypeScript-specific mistakes LLMs make repeatedly — weak types, unsafe assertions, and patterns that compile but fail at runtime.
Rule classification
- MUST — load-bearing. Violating leaks runtime errors past the type checker. Never break.
- SHOULD — default behavior. Deviation needs a documented reason in the code or PR.
- AVOID — usually wrong; documented exception inline where needed.
Where these rules don't strictly apply: test fixtures, generated types (e.g. from GraphQL codegen, OpenAPI generators, Prisma), declaration files (*.d.ts) for untyped third-party libraries, and migration scripts may legitimately differ. The rules below apply to production application code.
Type Safety
MUST: Never use
any. Useunknownand narrow it.anydisables the type checker entirely.unknownforces you to prove the type before use. Exception: third-party libraries without types and explicit dynamic-data boundaries (e.g. JSON parse at the API edge), with a comment explaining why.// Wrong function parse(data: any) { return data.name; } // Correct function parse(data: unknown): string { if (typeof data === 'object' && data !== null && 'name' in data) { return String((data as { name: unknown }).name); } throw new Error('Invalid data shape'); }AVOID:
Objector{}as a type. Both accept nearly everything. UseRecord<string, unknown>for arbitrary objects or define an explicit interface.// Wrong function merge(a: {}, b: Object): {} { ... } // Correct function merge<T extends Record<string, unknown>>(a: T, b: Partial<T>): T { ... }SHOULD: Use
asonly when you know more than the compiler — and document why. Prefer type guards orsatisfiesinstead.// Wrong — silences the error, hides the bug const user = response.data as User; // Correct — validate first function isUser(v: unknown): v is User { return typeof v === 'object' && v !== null && 'id' in v && 'email' in v; } const user = isUser(response.data) ? response.data : null;SHOULD: Mark immutable data
readonly. Prevents accidental mutation and communicates intent.// Avoid function process(ids: string[]) { ids.push('extra'); } // Prefer function process(ids: readonly string[]) { /* ids.push() is a compile error */ }MUST: Enable
strictNullChecksand handle everyT | undefined. Optional chaining?.returnsundefined— always handle that branch.// Wrong const name = user?.profile.name.toUpperCase(); // crashes if name is undefined // Correct const name = user?.profile.name?.toUpperCase() ?? 'Anonymous';SHOULD: Use branded types for IDs. Prevents passing a
UserIdwhere anOrderIdis expected — both arestringat runtime.type UserId = string & { readonly _brand: 'UserId' }; type OrderId = string & { readonly _brand: 'OrderId' }; function createUserId(raw: string): UserId { return raw as UserId; } function getUser(id: UserId): User { ... } // getUser(orderId) → compile error
Patterns
SHOULD: Use discriminated unions for state, not optional fields. Optional fields force you to reason about all combinations. A discriminated union makes illegal states unrepresentable.
// Avoid — 8 possible combinations, most invalid type Request = { loading?: boolean; data?: User; error?: Error }; // Prefer — exactly 3 valid states type Request = | { status: 'idle' } | { status: 'loading' } | { status: 'success'; data: User } | { status: 'error'; error: Error };SHOULD: Use
satisfiesto validate shape without widening the type.as constpreserves literals;satisfiesvalidates against an interface without losing them.const config = { host: 'localhost', port: 5432, } satisfies DatabaseConfig; // config.port is still typed as 5432, not numberSHOULD: Use
constobjects instead ofenum. Enums emit runtime code, have surprising reverse-mapping behavior, and are not idiomatic TypeScript.// Avoid enum Direction { Up, Down, Left, Right } // Prefer const Direction = { Up: 'Up', Down: 'Down', Left: 'Left', Right: 'Right' } as const; type Direction = typeof Direction[keyof typeof Direction];AVOID: Barrel
index.tsre-exports in large modules. They cause circular dependency chains that are hard to debug. Export directly from source files or use explicit named re-exports only.// Wrong — index.ts re-exports everything, A imports B through index, B imports A through index export * from './userService'; export * from './orderService';
Установить typescript в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл typescript?
Apply when writing TypeScript code. Strict types, discriminated unions, async patterns, and runtime safety.
Как установить скилл typescript?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл typescript запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
от Anthropicacademy-guide
Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
от Anthropicinternal-comms
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
от Anthropicskill-development
This skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…
от Anthropic