typescript-discipline
TypeScript type-design criteria (unions, brands, parsing at boundaries, schema-first validation, exhaustiveness, no unchecked casts) that the orchestrator…
by Motaghi★ 51 GitHub stars
Install typescript-discipline in Claude Code & Claude Desktop
Sign up to install this skill
Create a free account to reveal the install command and save the skill to your library.
- Reveal the one-line install command
- Save skills to your synced library
- Get notified when skills update
About this skill
typescript-discipline
A reference package of TypeScript criteria in one merged rule set. The rules say how to design types so that the compiler rules out impossible states, mixed-up values and unhandled cases, and how to treat data that comes from outside. The package holds criteria only. It does not give a general code review or a merge verdict, run a build, write code or configure tooling.
How it is used
A user or orchestrator naming this skill, by name or slash command, or attaching it as a labeled input, counts as activation. The agent's own choice to load it does not. The rule numbers, the rule table and the hot-path exceptions are defined only in SKILL.md, so a reference file attached alone does not activate anything. references/upstream-notice.md is provenance and never counts as an attachment. Without activation, ordinary questions are answered normally, without the numbered report.
When the rules are active, the person or sub-agent doing the work applies them to the code in front of them and reports each rule by number as met, failed, not applicable or unverified. Every rule from 1 to 16 appears in the report, for each item reviewed; rules that share a result may be grouped as a numbered range, such as "rules 2 to 13: unverified, no declaration shown", but no rule is left out or covered only by a general sentence. A met or failed result cites the place that shows it: a type declaration, a call site, a file and line. A rule with no such evidence is reported as unverified, not estimated.
The package never dispatches anything, never picks a model or provider, and never commits, pushes or installs anything. If a request asks it to do any of those, it hands the decision back to the orchestrator. It does not apply to ordinary TypeScript conversation such as syntax, library use or how to write a generic; those questions are answered without it.
Required capabilities
filesystemto read the files in this package and the TypeScript under review. Nothing is written.
If a file that a rule depends on cannot be read, mark that rule unverified. Do not guess, and do not substitute another source.
Rules
| # | Rule | What to check |
|---|---|---|
| 1 | Discriminated unions | Variants carry a literal discriminant such as kind, so impossible combinations cannot be written. No bags of optional fields. If a comment has to say when a combination of fields is valid, the type is too loose. |
| 2 | Constructive modeling | Build the type from parts that are all legal: [T, ...T[]] for non-empty, [T, T][] for even length, a start plus a duration for a range, made only through a constructor that validates its inputs, with the validated values held in #private slots. Do not carve a loose type down with a runtime guard that every caller must repeat. |
| 3 | Simplest total type | Keep T[] while every operation on it stays total. Strengthen it only where the loose type forces a !, a cast or a "should never happen" throw. Widening the result to include undefined is the other total signature. |
| 4 | Branded types | Brand primitives that mean different things, such as two kinds of id. Validate once at creation with a verifying guard or a parse function, never with as. Match the brand shape the repository already uses. |
| 5 | unknown over any |
External data is unknown until parsed. Narrow before use. |
| 6 | Parse at the boundary | Turn input into a named domain type where it crosses in. Record<string, unknown>, however it is spelled, stops at that parse. Trust the types inside, and do not re-validate deep in a call chain. Where validation belongs is decided by the boundary-discipline file of engineering-principles. |
| 7 | Schema first | Before writing a property-by-property guard for external data, use the repository's own schema library and infer the type from the schema. The package requires no specific library. A new schema dependency is not added for one guard. With no schema library in the repository, a guard that checks every property is acceptable, and adding a library goes to the orchestrator as the owner's decision, as does any request to add or switch one. |
| 8 | No unchecked as |
Cast only after validation. as unknown as T and assertion functions that skip checking are lies to the compiler. If the compiler cannot prove a fact, prove it by validating, narrowing or refining the model, or name the cast as a hazard. |
| 9 | Narrowing order | Prefer a discriminant switch, then in, then typeof or instanceof, then a user-defined guard, and as last. |
| 10 | Honest guards | A type guard must verify the claim its signature makes. A lying guard is worse than as, because the bug hides behind a name that sounds safe. Name guards isX or hasX. |
| 11 | Exhaustiveness | In the default arm, assign the narrowed union value to a local of type never, so adding a variant stops the build until it is handled. |
| 12 | satisfies over as |
Use satisfies to check a |
Allowed tools
Tools this skill is permitted to call.
No restriction — this skill can use any tool.
Bundled files
- references/patterns.md
- references/type-system.md
- references/upstream-notice.md
FAQ
What does the typescript-discipline skill do?
TypeScript type-design criteria (unions, brands, parsing at boundaries, schema-first validation, exhaustiveness, no unchecked casts) that the orchestrator attaches as a labeled input or a sub-agent reaches by pointer. Not for React or Next.js component and framework questions or merge verdicts. Use when the user or the orchestrator names this skill. Edits nothing.
How do I install the typescript-discipline skill?
Copy the skill folder into ~/.claude/skills (the Claude Code tab above does this in one command), or install it as a plugin.
Does the typescript-discipline skill run scripts?
No, this skill is instructions only (SKILL.md) with no executable scripts.
Related skills
frontend-design
AnthropicGuidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making…
webapp-testing
AnthropicToolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing…
brand-guidelines
AnthropicApplies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand…
web-artifacts-builder
AnthropicSuite of tools for creating elaborate, multi-component claude.ai HTML artifacts using modern frontend web technologies (React, Tailwind CSS, shadcn/ui). Use…