writing-typescript
Imported from alexei-led/cc-thingz/dist/pi/skills/writing-typescript.
Install
npx skills add https://github.com/alexei-led/cc-thingz/tree/master/dist/pi/skills/writing-typescript
claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install alexei-led-cc-thingz@llmmart
git clone https://github.com/alexei-led/cc-thingz.git
The skills CLI installs just this skill, for any of its supported agents. Claude Code installs the whole alexei-led/cc-thingz collection as a plugin from our marketplace. Git is the plain clone.
Skill manifest
TypeScript Development
Follow the repository's TypeScript version, tsconfig, package manager, framework, and test runner. In a monorepo, work from the nearest package.json and tsconfig.json and name the package you chose.
Defaults
- Never weaken compiler options to pass a check. New configs enable
strict,noUncheckedIndexedAccess,exactOptionalPropertyTypes,useUnknownInCatchVariables,noImplicitOverride, andnoFallthroughCasesInSwitch. - Treat HTTP responses, JSON, env, storage, form data, and SDK output as
unknown. Narrow at the boundary with the project's schema library or a small type guard; never castawait res.json()to a domain type. - Avoid
any,ascasts, non-null!, and broad index signatures unless a runtime check or an external type gap justifies them. - Discriminated unions for variants and async state, with an exhaustive
nevercheck. Literal unions oras constarrays instead of new enums.satisfiesfor config maps. - Result unions for recoverable failures callers must branch on; throw
Errorinstances otherwise. - Pass dependencies as parameters; no singletons or hidden module state. Thread
AbortSignalthrough work that can outlive its caller. - Ask before adding a schema, form, query, or state library the project does not already use.
React
- Plain function components, not
React.FC. TypechildrenasReactNode. - Derive state during render. Fix stale closures instead of suppressing exhaustive-deps.
- Add
memo,useMemo, oruseCallbackonly for measured cost or a real identity need. - Validate fetched data in the fetcher, not in render. Custom hooks throw when their provider is missing.
Tooling
Typecheck with the project script or tsc --noEmit. Use one formatter and one linter per file; the selection order is in linting.md.
References
- testing.md: read when adding or changing tests, including React component tests.
- linting.md: read when choosing a formatter or linter, changing lint config, or diagnosing slow lint.
Done when the relevant build/test/lint checks pass on what you changed, or you name each check that did not run and why.
Files (cc-thingz)
-
references
-
linting.md 1.7 KB
# TypeScript Linting ## Tool Selection Use the project's lint and format scripts first. Pick one formatter and one linter per file: - Project config and package declarations decide. When several are declared, prefer Oxfmt, then Biome, for formatting, and Oxlint, then Biome, for linting. - With no project choice, use an installed Oxfmt or Biome, else Prettier, for formatting; an installed Oxlint or Biome, else ESLint, for linting. - Never run overlapping Biome and ESLint lint passes. ## Edit Loop Safe fixes in file-modifying hooks, scoped to changed files: ```bash oxfmt --write path/to/changed.ts biome format --write path/to/changed.ts biome lint --write path/to/changed.ts oxlint --fix path/to/changed.ts ``` - Commit and CI checks stay non-mutating (`biome lint`, `oxlint`, `eslint`). - Use package scripts for whole-project checks instead of widening a file-scoped command. - Clear lint caches only when diagnosing cache corruption. - `--quiet` skips warn-level rules; use it only for a focused hot-path error check. ## Type-Aware Lint - It costs about as much as a TypeScript build. Keep a cheaper syntax/style path for the edit loop when many rules are type-aware. - Point typed lint at package-level tsconfigs, not recursive globs, and keep `include` away from build output, generated files, and fixtures. - Keep the project's typescript-eslint setup (project service or explicit projects). Ask before rewriting lint architecture for speed. ## Slow Lint - Profile with `TIMING=1 eslint .`. The first type-aware rule looks slow because it pays TypeScript setup, so compare slow rules one at a time. - Use `eslint --debug` only while diagnosing. - Do not lower severity, disable rules, or ignore files to go faster. Split a hot-path command from the full gate instead. -
testing.md 1.2 KB
# TypeScript Testing ## Style - Use the project's runner and helpers. With Vitest, type mocks with `vi.mocked` and reset only the mocks, timers, and globals a test changes. - HTTP: prefer the project's MSW or HTTP harness over mocking `fetch`. No untyped `as Response` mocks. - Boundary validation code gets malformed-JSON and wrong-shape tests, plus timeout and cancellation cases when the code handles them. - Replace real sleeps with fake timers, controlled promises, or poll-until helpers with hard timeouts. ## React - Test user-visible behavior with Testing Library. Query by role and accessible name first; use `userEvent` when the project has it. - Cover the loading, empty, error, disabled, and validation states the change touches. ## Fast Loop - Run pure logic tests in the cheapest environment (`node`, not `jsdom` or a browser) unless behavior needs the DOM. - Keep coverage, open-handle diagnostics, browser, and end-to-end runs off the hot path unless they are the task. - Keep global setup and preload files small so focused runs stay focused. - Tune worker counts only after measuring; transforms, DOM environments, and memory often make more workers slower.
-
-
SKILL.md 2.9 KB
--- {"description":"Idiomatic TypeScript development. Use when writing TypeScript code, Node.js services, React apps, or TypeScript design advice. Emphasizes strict typing, boundary validation, composition, fast feedback, behavior tests, and project-configured tooling. NOT for Go, Python, Rust, plain HTML/CSS/JS, or server-rendered templates (use writing-web).","name":"writing-typescript"} --- <!-- Pi platform guidance --> <!-- Use installed Pi tool names exactly, including extension toolsets such as Task*, Monitor*, and Loop*. --> <!-- When available, track work with Task* (`todo` is the fallback), run long or background commands with MonitorCreate, and schedule follow-up with LoopCreate instead of sleep/poll loops. --> # TypeScript Development Follow the repository's TypeScript version, tsconfig, package manager, framework, and test runner. In a monorepo, work from the nearest `package.json` and `tsconfig.json` and name the package you chose. ## Defaults - Never weaken compiler options to pass a check. New configs enable `strict`, `noUncheckedIndexedAccess`, `exactOptionalPropertyTypes`, `useUnknownInCatchVariables`, `noImplicitOverride`, and `noFallthroughCasesInSwitch`. - Treat HTTP responses, JSON, env, storage, form data, and SDK output as `unknown`. Narrow at the boundary with the project's schema library or a small type guard; never cast `await res.json()` to a domain type. - Avoid `any`, `as` casts, non-null `!`, and broad index signatures unless a runtime check or an external type gap justifies them. - Discriminated unions for variants and async state, with an exhaustive `never` check. Literal unions or `as const` arrays instead of new enums. `satisfies` for config maps. - Result unions for recoverable failures callers must branch on; throw `Error` instances otherwise. - Pass dependencies as parameters; no singletons or hidden module state. Thread `AbortSignal` through work that can outlive its caller. - Ask before adding a schema, form, query, or state library the project does not already use. ## React - Plain function components, not `React.FC`. Type `children` as `ReactNode`. - Derive state during render. Fix stale closures instead of suppressing exhaustive-deps. - Add `memo`, `useMemo`, or `useCallback` only for measured cost or a real identity need. - Validate fetched data in the fetcher, not in render. Custom hooks throw when their provider is missing. ## Tooling Typecheck with the project script or `tsc --noEmit`. Use one formatter and one linter per file; the selection order is in linting.md. ## References - [testing.md](references/testing.md): read when adding or changing tests, including React component tests. - [linting.md](references/linting.md): read when choosing a formatter or linter, changing lint config, or diagnosing slow lint. Done when the relevant build/test/lint checks pass on what you changed, or you name each check that did not run and why.
Comments (0)
Sign in to join the conversation.
Reviews (0)
No reviews yet.
No comments yet.