agentleFS
ngxcccngxccc/engineered-skills/skills/typescript-best-practices/SKILL.md

typescript-best-practices

Skill0 starsChanged 58 days agoMITView on GitHub

Enforce strict TypeScript type-system and boundary discipline when reading or writing .ts and .tsx files. Use whenever authoring, reviewing, or refactoring TypeScript code.

99 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use setup-pstack, make-bot-ui and 4 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.
  • bnemaSkill

    setup-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 24 projects that use this

  • eryzerzSkill

    make-bot-ui

    Use when building a custom UI (page, dashboard, buttons) that should wake a Grok Bot over a webhook, when the user must provide a webhook sender key, or when exposing that UI on Tailscale.

    Also in 15 projects that use this

  • shiwenbin1617Skill

    ketchup-video

    Catch the user up like /ketchup, with a short subtitled video of slides for what happened and the waiting calls as text under it. Use for /ketchup-video.

    Also in 10 projects that use this

  • shiwenbin1617Skill

    statechart

    Check a TLA+ model of a system that moves between states, such as a product flow, a protocol, or a service, and draw it as a Mermaid statechart. The report gives the shortest path to each state that breaks a rule. Use for /statechart, or to show a bug as a path through states.

    Also in 11 projects that use this

  • mukcoSkill

    principles

    General software engineering principles — DRY, SOLID, YAGNI, KISS, naming, code smells, and refactoring. Language-agnostic. Use alongside language-specific skills.

    Also in 4 projects that use this

  • rohunvoraSkill

    reframe

    This skill should be used when the user is stuck, obvious solutions aren't working, constraints feel impossible, or they keep circling back to bad options. Use when designs keep getting rejected or the user is solving symptoms instead of root causes.

    Also in 3 projects that use this

The file

We split this skill into the rules it gives an agent

5 rules. 0 are common, 1 is distinctive, and 4 are very specific to this project.

  • 0

    Common

    Most of the 29 edited versions we read keep these.

  • 1

    Distinctive

    This author's own choices. Worth a look.

  • 4

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use the type system to make invalid states unrepresentable at compile time rather than treating TypeScript as annotated JavaScript.

    line 11
  2. Very specific:

    unknown over any: treat unparsed external data as unknown and narrow before use.

    line 17
  3. Very specific:

    No unsafe as casts: avoid as Type assertions that silence the compiler.

    line 18
  4. Very specific:

    Narrowing hierarchy: prefer switch on a discriminant > in operator > typeof/instanceof > user-defined type guards.

    line 19
  5. Very specific:

    Exhaustiveness checking: add const _exhaustive: never = value.

    line 20

“Common” is measured: kept by at least 6 in 10 of the 29 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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

TypeScript Best Practices

Use the type system to make invalid states unrepresentable at compile time rather than treating TypeScript as annotated JavaScript.

Core Rules

  1. Discriminated unions over property bags: model distinct states with a literal discriminant (kind: "loading" | "ready" | "error") instead of optional fields that allow contradictory combinations.
  2. Branded types for domain IDs: brand primitives (type UserId = string & { readonly __brand: "UserId" }) so mismatched identifiers fail at compile time.
  3. unknown over any: treat unparsed external data as unknown and narrow before use; never disable checking with any.
  4. No unsafe as casts: avoid as Type assertions that silence the compiler; validate or narrow instead.
  5. Narrowing hierarchy: prefer switch on a discriminant > in operator > typeof/instanceof > user-defined type guards.
  6. Exhaustiveness checking: add const _exhaustive: never = value; in default branches so new union variants break at compile time.
  7. satisfies over as: validate object literals against a type with satisfies to preserve literal inference.
  8. Boundary validation: parse and validate untrusted inputs (HTTP, env, JSON, IPC) at system boundaries (e.g., Zod) so internal code trusts the resulting types.
  9. Constructive modeling: build types that encode invariants directly (e.g., [T, ...T[]] for non-empty arrays) instead of checking .length > 0 everywhere.

Deterministic Enforcement

Pair prose rules with compiler and linter gates so agents cannot bypass them:

  • tsconfig.json: enable strict, noUncheckedIndexedAccess, and exactOptionalPropertyTypes.
  • oxlint: enable typescript/no-explicit-any and typescript/no-unsafe-type-assertion (or consistent-type-assertions).

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.