agentleFS
amirrezaalastiamirrezaalasti/codescribe/skills/coding/typescript-best-practices/SKILL.md

typescript-best-practices

Skill2 starsChanged 4 months agoMITView on GitHub

Write strict, idiomatic TypeScript with sound types, narrowing, and clear API contracts. Use when writing or refactoring TypeScript, adding types to JS, designing interfaces, fixing type errors, or when the user mentions tsconfig, generics, or typed APIs.

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 10 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, 2 are distinctive, and 3 are very specific to this project.

  • 0

    Common

    Most of the 29 edited versions we read keep these.

  • 2

    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
  1. Distinctive:

    Match existing tsconfig and patterns: Do not loosen strictness to silence errors.

    line 29
  2. Very specific:

    Model the domain: Prefer precise union types and discriminated unions over optional soup (status: 'ok' | 'error').

    line 30
  3. Very specific:

    Narrow before use: Use type guards, in checks, and exhaustiveness (switch + never) for unions.

    line 31
  4. Distinctive:

    Generics when they remove duplication: Add type parameters for reusable containers/helpers.

    line 33
  5. Very specific:

    Tag unfinished or risky work: Use the global tagged-code-comments convention (🔴 FIXME(P0):, 🟠 TODO(P1):, …).

    line 36

“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

Defaults

ConcernDefault
StrictnessPrefer strict: true (and project-equivalent flags)
ModulesESM + project moduleResolution (often bundler or NodeNext)
Types vs interfacestype for unions/intersections/aliases; interface for object shapes meant to be extended
anyAvoid; use unknown + narrowing instead
AssertionPrefer narrowing over as casts; never as any unless escaping a known lib bug

Instructions

  1. Match existing tsconfig and patterns. Do not loosen strictness to silence errors; fix types or narrow correctly.
  2. Model the domain. Prefer precise union types and discriminated unions over optional soup (status: 'ok' | 'error').
  3. Narrow before use. Use type guards, in checks, and exhaustiveness (switch + never) for unions.
  4. Type public APIs thoroughly. Exported functions, hooks, and components should not rely on inference alone when the contract matters to callers.
  5. Generics when they remove duplication. Add type parameters for reusable containers/helpers; do not invent complex generics for one-off code.
  6. Avoid unsafe escapes. Limit ! non-null assertions; document why if unavoidable.
  7. Keep runtime and types aligned. Zod/Valibot (or similar) at boundaries when the project uses them — types alone do not validate external data.
  8. Tag unfinished or risky work. Use the global tagged-code-comments convention (🔴 FIXME(P0):, 🟠 TODO(P1):, …). Never leave silent stubs or as any escapes without a tag. End with an Open follow-ups table so the developer must check P0/P1 before ship.

Patterns

type Result<T> =
  | { ok: true; value: T }
  | { ok: false; error: string };

function unwrap<T>(r: Result<T>): T {
  if (!r.ok) throw new Error(r.error);
  return r.value;
}
type Shape =
  | { kind: "circle"; radius: number }
  | { kind: "rect"; width: number; height: number };

function area(s: Shape): number {
  switch (s.kind) {
    case "circle":
      return Math.PI * s.radius ** 2;
    case "rect":
      return s.width * s.height;
    default: {
      const _exhaustive: never = s;
      return _exhaustive;
    }
  }
}

Anti-patterns

  • Widespread any / as unknown as T
  • Optional fields for mutually exclusive states instead of discriminated unions
  • Overly wide types (string where a literal union works)
  • Duplicating runtime validation and types that drift apart

Additional resources

  • references/checklist.md

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.