agentleFS
crustacean-devcrustacean-dev/stack-guardrails/skills/typescript/SKILL.md

typescript

Skill0 starsChanged 8 months agoMITView on GitHub

Enforces strict TypeScript guardrails whenever writing, reviewing, refactoring, or generating .ts/.tsx/.mts/.cts code. Applies automatically to any TypeScript task — creating functions, components, types, configs, utility libraries, or converting JS to TS. Catches violations like enum (use as const), any (use unknown), default exports, barrel files, empty catch blocks, var, @ts-ignore, missing return types, and non-readonly properties. Also triggers for tsconfig changes, React/JSX with TypeScript props, API clients, CLI tools, and code reviews mentioning type safety. If the file extension or code context is TypeScript, use this skill — even if the user doesn't say 'TypeScript' explicitly.

33 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use python, react 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.
  • rogue-dev-studioSkill

    python

    Python 3.13 with uv package manager via mise. Use when the project needs this capability or the user / team manifest asks for it. Use for specialized `python` work when listed in TEAM.yaml or explicitly requested.

    Also in 9 projects that use this

  • VercelSkill

    react

    React renderer for json-render that turns JSON specs into React components. Use when working with @json-render/react, building React UIs from JSON, creating component catalogs, or rendering AI-generated specs.

    Also in 6 projects that use this

  • 0xSeroSkill

    security

    Also in 4 projects that use this

  • BlockSkill

    debugging

    Debugging guidelines and best practices

    Also in 3 projects that use this

The file

We split this skill into the rules it gives an agent

8 rules. 0 are common, 1 is distinctive, and 7 are very specific to this project.

  • 0

    Common

    Most of the 27 edited versions we read keep these.

  • 1

    Distinctive

    This author's own choices. Worth a look.

  • 7

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    DO NOT: use enum. Use as const objects + inferred type instead.

    line 14
  2. Very specific:

    DO NOT: use any. Use unknown with type guards to narrow.

    line 24
  3. Very specific:

    DO NOT: use type assertions (as X) unless no alternative exists.

    line 28
  4. Very specific:

    "noUncheckedIndexedAccess": true: when the project supports it.

    line 65
  5. Very specific:

    DO NOT: use @ts-ignore. Use @ts-expect-error with an explanation comment if suppression is truly needed.

    line 67
  6. Very specific:

    DO NOT: use non-null assertions (!) unless provably safe.

    line 69
  7. Distinctive:

    Discriminated unions over type predicates: when modeling variants.

    line 85
  8. Very specific:

    Avoid throw in library code: when possible. Prefer a Result pattern or explicit error returns:

    line 111

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

These are hard rules. Check every piece of TypeScript you write, review, or modify against this list.


Types

  • DO NOT use enum. Use as const objects + inferred type instead.
    // wrong
    enum Status { Active, Inactive }
    
    // correct
    const STATUS = { Active: 'active', Inactive: 'inactive' } as const;
    type Status = typeof STATUS[keyof typeof STATUS];
  • DO NOT use any. Use unknown with type guards to narrow.
  • Prefer type over interface unless you need declaration merging, extends, or implements.
  • DO NOT use type assertions (as X) unless no alternative exists. Narrow with control flow instead. If unavoidable, add a comment explaining why.
    • Only exception: as Record<string, unknown> inside type guards, to access properties on a narrowed object. No other as casts — validate with typeof, in, or equality checks. When checking membership in a const object, widen the array type to ReadonlyArray<string> instead of casting the value:
      function isUser(value: unknown): value is User {
        if (typeof value !== 'object' || value === null) return false;
        const obj = value as Record<string, unknown>; // only acceptable assertion
        const validRoles: ReadonlyArray<string> = Object.values(USER_ROLE);
        return typeof obj.name === 'string' && typeof obj.role === 'string' && validRoles.includes(obj.role);
        // ↑ widen to ReadonlyArray<string> — do NOT cast obj.role as SomeType
      }
  • Use satisfies for type-safe object literals where you want inference + validation.
    const config = { port: 3000, host: 'localhost' } satisfies ServerConfig;
  • Explicit return types on all exported functions.

Imports / Exports

  • No barrel files (index.ts re-exports) except designated package entry points.
  • Explicit import paths — import { bar } from './utils/bar', not from './utils'.
  • No default exports except config files (vite.config.ts, eslint.config.ts, etc.). Use named exports everywhere else.
  • ESM only — import/export. Never require() or module.exports.

Strict Mode

  • "strict": true in tsconfig — always. Do not loosen individual strict flags.
  • "noUncheckedIndexedAccess": true when the project supports it.
  • DO NOT use @ts-ignore. Use @ts-expect-error with an explanation comment if suppression is truly needed.
  • DO NOT use non-null assertions (!) unless provably safe. If used, add a comment explaining the proof.

Patterns

  • const by default. let only when reassignment is needed. Never var.
  • Exhaustive switches — always include a default case with a never check:
    default: {
      const _exhaustive: never = value;
      throw new Error(`Unhandled case: ${_exhaustive}`);
    }
  • Discriminated unions over type predicates when modeling variants.
  • Readonly by default — use readonly properties, ReadonlyArray<T>, Readonly<T>.
  • No classes unless required by a framework (e.g., Angular, NestJS). Prefer functions + closures.

Naming

ThingConventionExample
Fileskebab-caseuser-service.ts
Types / InterfacesPascalCaseUserProfile
Functions / variablescamelCasegetUserById
ConstantsUPPER_SNAKE_CASEMAX_RETRY_COUNT
Schema interfaces<Name>SchemaUserSchema

Error Handling

  • Never swallow errors — no empty catch blocks. Log, rethrow, or handle explicitly.
  • Typed errors — use custom error classes or discriminated union result types.
  • Avoid throw in library code when possible. Prefer a Result pattern or explicit error returns:
    type Result<T, E = Error> = { ok: true; value: T } | { ok: false; error: E };

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.