1---2description: Idiomatic TypeScript development. Use when writing TypeScript code, Node.js3 services, React apps, or TypeScript design advice. Emphasizes strict typing, boundary4 validation, composition, fast feedback, behavior tests, and project-configured tooling.5 NOT for Go, Python, Rust, plain HTML/CSS/JS, or server-rendered templates (use writing-web).6name: writing-typescript7metadata:8 source: https://skillmd.com/skills/alexei-led/writing-typescript9---1011# TypeScript Development1213## Scope1415- Use for `.ts` and `.tsx`, Node.js services, React apps, typed APIs, and TypeScript design advice.16- Do not use for Go, Python, Rust, plain HTML/CSS/JS, or server-rendered templates.17- Follow the repository's TypeScript version, tsconfig, package manager, framework, test runner, and lint rules.18- Do not add dependencies or switch frameworks unless the project already uses them or the user approves.1920## Reference Reads2122- Read only the references needed for the task.23- Read `references/principles.md` for non-trivial TypeScript changes or reviews.24- Read `references/patterns.md` for data models, validation, async flow, or module boundaries.25- Read `references/react.md` for `.tsx`, hooks, component state, forms, performance, or React tests.26- Read `references/testing.md` before adding or changing TypeScript tests.27- Read `references/linting.md` before changing lint config, lint commands, or slow lint workflows.2829## Defaults3031- Preserve strict typing; do not weaken compiler options to pass checks.32- Use `unknown` for untrusted input. Avoid `any`; isolate it only for unavoidable interop.33- Validate API, JSON, env, storage, and form data at the boundary before typed use.34- Use discriminated unions for variants, async state, and domain states.35- Use guard clauses and focused helpers. Avoid deep nesting, global state, and mixed concerns.36- Use the project's error conventions; prefer unions or `Result` for recoverable failures.37- Pass dependencies explicitly; avoid inheritance, singletons, and hidden module state.38- Avoid unsafe casts, non-null assertions, broad index signatures, boolean-flag state, and new app enums where literal unions fit.3940## Comments and JSDoc4142- Use JSDoc or TSDoc for exported APIs and non-obvious public properties or methods.43- Avoid merely restating property, parameter, or type names.44- Add implementation comments only for non-obvious constraints, invariants, side effects, tradeoffs, or interoperability quirks.45- Keep comments short. Move longer rationale to docs, issue links, or design notes.46- Do not comment obvious code.47- Keep tests readable without comments; add one only for unobvious fixtures, timers, concurrency, browser setup, or regression context.4849## Testing and Verification5051- For behavior changes, include success and failure tests. For React, cover affected user-visible states.52- Use focused test, typecheck, and lint commands for the changed file, package, or workspace while editing.53- Run the project's configured typecheck, tests, lint, and format checks for the changed package or workspace before final output.54- Keep coverage, end-to-end tests, and expensive debug diagnostics off the hot path unless they are the task.55- Report checks run, failures, and unchecked risks. Do not claim success without a clean check or an explicit reason it was skipped.5657## Failure Handling5859- If project root is unclear, identify the nearest `package.json` and `tsconfig.json`; in monorepos, state the selected package.60- If strict compiler options are absent, do not silently weaken new code. State the gap and keep the change locally type-safe.61- If validation needs a schema/form library not already used, ask before adding it; otherwise use a narrow type guard.62- If typecheck or tests fail, quote the exact diagnostic or failing assertion, state the cause, and fix the type/model boundary before widening types.63- Do not run destructive shell commands. For broad or risky changes, state the risk and ask before acting.6465## Final Response6667- Files changed:68- Checks:69- Skipped checks:70- Risks/follow-ups: