typescript-best-practices
Skill4 starsChanged 15 days agoMITView on GitHub
Sixteen type-safety rules for writing and reviewing TypeScript, with do and don't examples in references/patterns.md. Use whenever you open or edit a .ts or .tsx file, or on /typescript-best-practices.
77 other projects use a version of this.
Adopted by
Most recently taken up by
- Yeachan-Heo/oh-my-claude-sisyphustheir own version, first seen Nov 8, 2026
- caidanw/skillstheir own version, first seen Nov 8, 2026
- trpc/trpctheir own version, first seen Nov 8, 2026
- Yeachan-Heo/oh-my-claudecodetheir own version, first seen Nov 8, 2026
- endqwerty/endstacktheir own version, first seen Nov 8, 2026
- tristanphvn/keeltheir own version, first seen Nov 8, 2026
Used with
Projects with it also use setup-pstack, poteto-help and 2 more.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
bnemaSkillsetup-pstack
Configure which Pi models pstack uses per role. Detects available provider/model specs and writes pstack's user configuration. Use for /setup-pstack, "configure pstack models", or changing pstack model choices.
Also in 22 projects that use this
ianclearySkillpoteto-help
Guides users through pstack setup, /poteto-mode, and picking the skill, playbook, or principle for a task. Type /poteto-help with a question.
Also in 12 projects that use this
tristanphvnSkillketchup-video
Catch the user up like /keel:ketchup, with a short silent video of slides for what happened and the waiting calls as text under it. Use for /keel:ketchup-video.
Also in 8 projects that use this
instructureSkillketchup
Rebuild context after /clear by analyzing uncommitted changes across Canvas LMS and all plugin repositories
Also in 17 projects that use this
Other versions77 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 77
- trpc/trpc★ 41ksame name
- Yeachan-Heo/oh-my-claude-sisyphus★ 41ksame name
- Yeachan-Heo/oh-my-claudecode★ 41ksame name
- backnotprop/pstack★ 3.8ksame name
- jtaroreh/agystack★ 128same name
- uzairansaruzi/p3-stack★ 126same name
- dsebban/skills★ 71same name
- baekenough/oh-my-customcode★ 42same name
- overextended/skills★ 22same name
- TheOnlyFusionCube/potetos-for-everyone★ 21same name
67 more not listed
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 repository61 other files it gives its agents.
- architectSkill
- arenaSkill
- automate-meSkill
- benchmark-checklistSkill
- blast-radiusSkill
- broSkill
- catch-upSkill
- catch-up-videoSkill
- correctSkill
- create-formal-verification-skillSkill
- create-verification-skillSkill
- figure-it-outSkill
- howSkill
- interrogateSkill
- in-your-own-wordsSkill
- maintain-formal-verification-skillSkill
- maintain-verification-skillSkill
- make-bot-uiSkill
- no-commentsSkill
- principle-attack-the-premiseSkill
- principle-boundary-disciplineSkill
- principle-build-the-leverSkill
- principle-encode-lessons-in-structureSkill
- principle-exhaust-the-design-spaceSkill
- principle-experience-firstSkill
- principle-explain-the-numberSkill
- principle-fix-root-causesSkill
- principle-foundational-thinkingSkill
- principle-guard-the-context-windowSkill
- principle-laziness-protocolSkill
- principle-make-operations-idempotentSkill
- principle-migrate-callers-then-delete-legacy-apisSkill
- principle-minimize-reader-loadSkill
- principle-model-the-domainSkill
- principle-never-block-on-the-humanSkill
- principle-outcome-oriented-executionSkill
- principle-prove-it-worksSkill
- principle-redesign-from-first-principlesSkill
- principle-separate-before-serializing-shared-stateSkill
- principle-sequence-verifiable-unitsSkill
- principle-subtract-before-you-addSkill
- principle-test-behavior-not-implementationSkill
- principle-treat-input-as-untrustedSkill
- principle-type-system-disciplineSkill
- recallSkill
- reflectSkill
- security-reviewSkill
- setup-endostackSkill
- sharpenSkill
- show-me-your-workSkill
- statechartSkill
- swarmSkill
- tarique-helpSkill
- tarique-modeSkill
- tddSkill
- teachSkill
- technical-writingSkill
- threat-modelSkill
- try-endostackSkill
- unslopSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
4 rules. 0 are common, 1 is distinctive, and 3 are very specific to this project.
0
Common
Most of the 26 edited versions we read keep these.
1
Distinctive
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 9
Read principle-type-system-discipline (../principle-type-system-discipline/SKILL.md) first.
- Very specific: line 11
If your agent supports path-scoped skills, attach this one to /*.ts and /*.tsx.
- Distinctive: line 13
Before you write anything, find the repo's existing conventions: its schema library, its logger, the name it uses for union tags, and the …
- Very specific: line 32
Derive types from generated sources: When types already come from protobuf, OpenAPI, GraphQL, or database migrations, build on them with …
“Common” is measured: kept by at least 6 in 10 of the 26 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
typescript-best-practices
Read principle-type-system-discipline (../principle-type-system-discipline/SKILL.md) first. These rules apply it to TypeScript. references/patterns.md has a short code example for each rule, numbered to match.
If your agent supports path-scoped skills, attach this one to **/*.ts and **/*.tsx. Otherwise the router or the user loads it when TypeScript is in play. For other languages, use principle-type-system-discipline and principle-boundary-discipline (../principle-boundary-discipline/SKILL.md) directly.
Before you write anything, find the repo's existing conventions: its schema library, its logger, the name it uses for union tags, and the shape of its brand marker. Follow them over the examples in the reference.
Modeling
- Tagged unions for variants. Model alternative states as a union of object types that share one literal tag field. A boolean flag plus optional fields lets contradictory combinations exist (
loading: truewith anerrorset). Use one tag name across the codebase. - Branded primitives. Intersect a primitive with a readonly brand property so an
InvoiceIdcannot be passed where aCustomerIdis expected. Mint the brand only through a type guard that validates (value is InvoiceId) and a parse function that wraps the guard and throws on failure. Never brand withas. Check once where the value enters; downstream code trusts the brand. - Make illegal values unconstructible. Prefer a shape that cannot hold a bad value to a runtime check:
[T, ...T[]]for a non-empty list,Array<[K, V]>for paired data, a start plus a duration instead of start and end with an ordering invariant in a comment. Provide helpers for derived views (the computed end time). Brand the duration only if some unrelated number could be passed in its place. - Use the simplest type that keeps every operation total. A plain array is fine while every operation on it works for empty input (a sum of nothing is zero). Strengthen to non-empty only where the weak type forces a lie: a
!, an index cast, or an "unreachable" throw. Or widen the return type to includeundefined. Provide a guard so a plain array can be checked once and then carried as non-empty.
Untrusted data
- External data is
unknown, neverany. RPC payloads, parsed JSON,postMessageevents, IPC, files, environment variables, and database rows all arrive asunknownand get narrowed before use.anyturns off the checker exactly where an attacker controls the input. - Schemas before hand-written guards. Check whether the codebase uses a runtime validation library and already defines a schema for this data. Define one schema and infer the static type from it. Use the non-throwing parse call when bad input is an expected outcome (a user form), and the throwing one when it is a bug. Never add a validation library for one guard. If the static type already exists, annotate the schema with it so the compiler rejects a schema that checks less than the type promises.
- No
asexcept after validation. When you remove an assertion, find out why inference failed: add a missing discriminant, narrow a source typed asRecord<string, unknown>, parse at the untyped boundary with the owning schema, or, if the fact truly cannot be expressed, use a brand orsatisfies. - Narrow in this order, best first: switch on the tag; an
incheck;typeoforinstanceof; a custom guard; an assertion after validation. - Guards must check what they claim. A guard that lies is worse than
asbecause its name promises safety. Name guardsisXorhasX. Prefer tag narrowing when a tag exists. - Exhaustive switches. In the
defaultbranch of a switch over a union, assign the value to a local typednever. Adding a variant then fails to compile at every switch that forgot it. Return that local in value-returning switches; mark it used withvoidin statement switches. satisfiesoverasfor literals. It checks conformance and keeps the literal types.- Parse once at the boundary. Data crossing into the system is parsed once into a named domain type. A loose record type never travels past that parse. Wire formats tolerate unknown fields so older code can read newer messages. Persisted JSON is a versioned blob parsed inside
try/catch. Inner functions do not re-validate. Seeprinciple-boundary-discipline. - Derive types from generated sources. When types already come from protobuf, OpenAPI, GraphQL, or database migrations, build on them with
Pick,Omit,Partial, andtypeof. A hand-written duplicate interface drifts the first time the source changes.
Calls, tests, and telemetry
- One object parameter over several positional ones. Swapped positional arguments of the same type compile without complaint; named fields do not. Exempt hot paths (per-frame rendering, tokenizers, parsers, tight loops) where the allocation shows up in a profile.
- Run real code in tests. Do not mock what can run on a dev machine. Use the test framework's own facilities, including its checks for leaked handles and undisposed resources. Check UI behavior in a real running build. Keep mocks for dependencies that cannot run locally. See the
tddskill (../tdd/SKILL.md). - Structured telemetry. Log through the project's structured logger with enough fields that an id alone lets someone debug the case. No bare
console.login shipped code. Never log secrets, tokens, or full request bodies that may contain them.
Done when
No any touches external data, every as follows a validation, no guard lies, every switch over a union is exhaustive, and boundary data is parsed once into a domain type.
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.

