typescript-type-safety
Skill25 starsChanged 32 days agoMITView on GitHub
Use when changing TypeScript types, parsing input that enters typed code, or removing unsafe casts. Also use it when the user says "fix the types", "remove the as casts", or "make invalid states impossible". Models each valid state with types, so that invalid combinations fail to compile. Checks outside input with a type guard or a schema instead of an assertion. Not for designing module boundaries (use `design-deep-modules`).
2 other projects use a version of this.
Adopted by
Most recently taken up by
- catesandrew/skillstheir own version, first seen Nov 1, 2026
- pr-pm/prpmtheir own version, first seen Feb 24, 2026
Other versions2 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 2
- pr-pm/prpm★ 124same name
- catesandrew/skills★ 1same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository49 other files it gives its agents.
- AGENTS.mdAGENTS.md
- evals/AGENTS.mdAGENTS.md
- tooling/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- evals/CLAUDE.mdCLAUDE.md
- tooling/CLAUDE.mdCLAUDE.md
- choose-by-consequenceSkill
- design-deep-modulesSkill
- diagnose-before-editingSkill
- plan-with-review-pageSkill
- research-primary-sourcesSkill
- resolve-conflicts-by-intentSkill
- scope-confirmed-changesSkill
- shadowclone-build-preferencesSkill
- shadowclone-reviewSkill
- shadowclone-workSkill
- tests-that-catch-bugsSkill
- typescript-type-safetySkill
- verify-and-reviewSkill
- write-plain-englishSkill
- choose-by-consequenceSkill
- data-handlingSkill
- design-deep-modulesSkill
- diagnose-before-editingSkill
- plan-with-review-pageSkill
- research-primary-sourcesSkill
- resolve-conflicts-by-intentSkill
- scope-confirmed-changesSkill
- shadowclone-build-preferencesSkill
- shadowclone-reviewSkill
- shadowclone-workSkill
- tests-that-catch-bugsSkill
- verify-and-reviewSkill
- write-plain-englishSkill
- choose-by-consequenceSkill
- design-deep-modulesSkill
- diagnose-before-editingSkill
- guided-pr-reviewSkill
- plan-with-review-pageSkill
- research-primary-sourcesSkill
- resolve-conflicts-by-intentSkill
- scope-confirmed-changesSkill
- shadowclone-reviewSkill
- shadowclone-workSkill
- tests-that-catch-bugsSkill
- typescript-type-safetySkill
- verify-and-reviewSkill
- verify-review-findingsSkill
- write-plain-englishSkill
The file
We split this skill into the rules it gives an agent
8 rules. About 0 are common, 8 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈8
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 26
Keep the relation between keys and values with generics, mapped types, or a typed setter.
- Distinctive: line 30
Run the type check, and run the tests for the boundary checks.
- Distinctive: line 35
Easy route: Keep the cast, because the file usually has the right shape.
- Distinctive: line 42
Keep one source of truth for each discriminator.
- Distinctive: line 43
Keep literal types until a wider type is necessary.
- Distinctive: line 44
Put an imprecise library type in one adapter that returns a precise project type.
- Distinctive: line 45
Use a narrow assertion only for a fact that a runtime check cannot express, and write down why.
- Distinctive: line 46
Follow the stricter rules of the repository where they apply.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Represent State in TypeScript Types
Use when
Values change together, optional fields hide different states, outside input enters typed code, or the compiler asks for an assertion. Each of these signals a missing type or a missing check.
Gates
- Does each valid state have its own type, such as a member of a discriminated union?
- Does outside input enter as
unknown, and pass a type guard or a schema before use? - Is the code free of
any, non-null assertions, and casts, exceptas const? - Does each switch over a union handle each member, so that a new member fails to compile?
- Does a failure that callers must handle appear in the return type?
Process
- Name the valid states and the moves between them. Use a discriminated union when only some field combinations are valid.
- Keep the relation between keys and values with generics, mapped types, or a typed setter.
- Accept outside input as
unknown. Check it at the boundary with a schema or a type guard. - Narrow values with control flow, type guards, or destructuring. Make a valid absence explicit.
- Return a type that makes callers handle each meaningful failure.
- Run the type check, and run the tests for the boundary checks.
Example
Situation: A function reads a config file and casts the parsed JSON to Config.
Easy route: Keep the cast, because the file usually has the right shape.
Hidden cost: A config file with one wrong field passes the cast. The program fails later, far from the cause.
Best route: Parse the JSON with a schema at the boundary. Return a clear error that names the field.
Evidence: A test with a wrong field type now fails at the boundary with "sources.git-metadata: expected boolean". The type check passed with no cast left.
Guardrails
- Keep one source of truth for each discriminator.
- Keep literal types until a wider type is necessary.
- Put an imprecise library type in one adapter that returns a precise project type.
- Use a narrow assertion only for a fact that a runtime check cannot express, and write down why.
- Follow the stricter rules of the repository where they apply.
Completion
- The type that now rejects the invalid state.
- One example that the compiler now rejects, with its error line.
- The type check command and the boundary test command, with their result lines.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

