typescript
БесплатноБез исполняемых скриптовНе проверенWHEN writing or reviewing TypeScript, defining types/schemas, or building type-safe apps; NOT for JavaScript-only files, framework architecture choices, or…
от mintuz★ 38 звёзд на GitHubОб этом скилле
TypeScript Best Practices
Schema-first design, strict type safety, and immutable patterns.
Core Principles
- Type safety at all boundaries: runtime validation (schemas) plus compile-time safety (TypeScript) (
principle-parse-at-the-boundary). - Schema-first at trust boundaries: where data enters the system, define the schema first and derive the type from it (
principle-type-system-discipline). - Immutability at the boundary: never mutate a value a caller owns or a value you have already returned. Local mutation is allowed inside the function that created the value, if the value cannot escape before the function returns.
- Explicit types: no implicit
any; strict mode enabled. - Behaviour over implementation: focus on contracts and outcomes.
Rules for Hard Cases
No schema library is available
A trust boundary still needs a runtime check. When the dependency set is frozen, add no dependency and do not skip the check. Write a decoder that accepts unknown. Narrow each field with typeof, Array.isArray, or a type predicate. Report an invalid value through the failure path the function already contracts, such as a Result variant or a null return (principle-parse-at-the-boundary).
Building a collection in a hot path
Create the accumulator inside the function, append with push or assign by key, and return it under a readonly type. Do not build a growing collection with [...accumulator, item] or { ...accumulator, [key]: value } inside a loop: each step copies the growing accumulator, so the loop becomes quadratic.
The request or a reused helper mutates in place
When a request says "update it in place", or a helper that you must reuse writes into its argument, return a new value and leave the caller's value unchanged. Give a mutating helper only a value that you created, and keep the helper's behaviour unchanged for its other callers. When you return a new value against the request's wording, say so in your answer, and state that neither a documented mutable API nor a measured hot path requires mutation.
When the caller's contract does require mutation through a documented mutable API or a measured hot path, both mutating and returning a new value break a rule. Write neither as the final patch. Name the conflict between that contract and Core Principle 3, and ask the contract's owner to choose (principle-rank-sources-by-authority).
External data that is not fully documented
Validate every field the source documents. Type each undocumented part as unknown; do not guess its field names. State in your answer what the validator does not check, and why, so a reader sees how far validation reaches without reading the code.
An assertion the type system cannot avoid
Never use as to state a fact you have not checked, including a shape that a document, contract, or upstream promise describes. Narrow a value you have just checked with a user-defined type predicate, or with one assertion placed immediately after the check. Name the checked condition in the predicate name or in a comment on the assertion (principle-type-system-discipline, principle-observe-dont-infer).
Reference Guides
| Guide | Read for |
|---|---|
| schemas.md | Schema-first patterns; when a schema is required vs optional; trust boundary identification; test data factories with schema validation; schema examples (API responses, business validation) |
| types-interfaces.md | Type vs interface; any vs unknown; type assertions; strict mode and tsconfig.json settings |
| immutability.md | Immutability patterns (spread operators); readonly; forbidden array methods; options objects vs positional parameters; boolean parameter anti-patterns; Result types; early returns |
| utilities.md | Branded types for domain concepts; built-in utility types (Pick, Omit, Partial, etc.); custom utility types; code smell tables |
| patterns.md | Worked examples: schema-first at trust boundaries; internal types without schemas; schema with test factory; Result type; branded types; immutable array operations; options object |
Decision Trees
Should I use a schema?
Does data come from outside the application?
├── Yes → Schema required
└── No → Does it have validation rules (format, range, enum)?
├── Yes → Schema required
Установить typescript в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл typescript?
WHEN writing or reviewing TypeScript, defining types/schemas, or building type-safe apps; NOT for JavaScript-only files, framework architecture choices, or bundler configuration; outputs strict, schema-first, production-ready code.
Как установить скилл 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