TypeScript strict rules
Keeps TypeScript code fully type-safe under strict mode, with no any, no unchecked casts, validated external data and exhaustive unions. Use in any TypeScript project.
When you write or change TypeScript:
- Do not loosen the compiler settings. Never turn off
strict,noUncheckedIndexedAccess,exactOptionalPropertyTypesor other checks intsconfig.jsonto make an error go away; fix the code. - Do not use
any. Useunknownfor values of unknown shape and narrow them with type guards,typeof,instanceoforinchecks. If a third-party type forcesany, contain it in one small, typed wrapper. - Do not silence errors with
@ts-ignoreor@ts-nocheck. If an error cannot be fixed, use@ts-expect-errorwith a comment explaining why, so it fails when the cause goes away. - Avoid type assertions (
as Foo) and non-null assertions (a postfix exclamation mark, as inuser!.name). Prefer narrowing. Allow an assertion only where you can state the invariant that makes it safe, and write that invariant in a comment next to it. Never writeas unknown as Footo force a type. - Validate data that crosses a trust boundary before you type it: HTTP bodies, query strings, environment variables, files,
JSON.parseresults and third-party API responses. Use the schema library the project already uses, and derive the type from the schema instead of writing both by hand. - Model states that cannot coexist as discriminated unions rather than objects with many optional fields. Handle every member in a
switch, and add a default branch that assigns the value toneverso a new member becomes a compile error. - Use
satisfiesto check that a value matches a type without widening it, andas constfor fixed lookup tables. - Mark data that should not change as
readonly(readonly T[],Readonly<T>), especially function parameters. - Give exported functions explicit parameter and return types. Let inference handle local variables.
- Use
import typeandexport typefor type-only imports and exports. - Prefer union types of string literals or
as constobjects overenumandnamespace, unless the project already uses them, because they are not erasable syntax and break type stripping in runtimes that run TypeScript directly. - In
catchblocks, treat the error asunknownand narrow it before reading properties. - Never leave a promise floating.
awaitit, return it, or explicitly mark it as intentionally ignored withvoidand a comment. - Index access may return
undefined. Handle that case instead of asserting it away. - Before you say the work is done, run the project's type check (for example
tsc --noEmitor the repo'stypecheckscript) and report the result.
details
- kind
- Rule: standing instructions for everything the assistant does
- domain
- Software engineering
- category
- Conventions
- level
- Intermediate
- made for
- Software engineer, Frontend engineer, Backend engineer, Full-stack engineer
- risk
- read-only
- version
- v1.0.0 · incubating
- reviewed
- 2026-10-02
- works in
- Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Antigravity, OpenCode, Windsurf, Zed, Continue, AGENTS.md, ChatGPT, claude.ai
use in
npx @hermes-hq/hodios install typescript-strict-rules --target claude-codenpx skills add hermes-hq/hodios-dist --skill typescript-strict-rules -a claude-codeRules are always-on instructions, so they are not in the plugins: add the skill, or paste the text into CLAUDE.md.
more in conventions
All of ConventionsHTTP API design rules
Rules for HTTP APIs covering resource naming, status codes, problem+json errors, cursor pagination, idempotency keys and versioning. Load when designing or changing HTTP endpoints.
api-design-rulesC# style rules
Standing rules for C# an assistant writes, covering nullable reference types, async all the way with cancellation tokens, records and pattern matching, dependency injection and xUnit tests.
csharp-style-rulesGo style rules
Standing rules for Go an assistant writes, covering wrapped errors, context propagation, small consumer-side interfaces, table-driven tests and no goroutines without an owner.
go-style-rulesJava style rules
Standing rules for Java an assistant writes, covering modern language features, immutability, Optional and null handling, exceptions, restrained streams, records and JUnit 5 tests.
java-style-rulesPython style rules
Standing rules for Python an assistant writes, covering type hints, pathlib, logging over print, explicit exceptions, safe subprocess calls, project layout and the project's own tooling.
python-style-rulesReact component rules
Standing rules for React code an assistant writes, covering function components, the rules of hooks, colocated state, stable list keys, accessible markup and no effect-driven derived state.
react-component-rules