agentleFS
seven-hills-softwareseven-hills-software/skillwright-skills/typescript-strict/SKILL.md

typescript-strict

Skill0 starsChanged 5 months agoMITView on GitHub

Type-first TypeScript with no-any, exhaustive switches, and parse-don't-validate discipline at boundaries.

13 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use react-patterns, api-design and 1 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.
  • xenitV1Skill

    react-patterns

    Modern React patterns and principles. Hooks, composition, performance, TypeScript best practices.

    Also in 3 projects that use this

  • MicrosoftSkill

    api-design

    Guide for designing and documenting RESTful APIs. Use when asked to design an API, create endpoints, or document an API.

    Also in 5 projects that use this

  • Microsoft AzureSkill

    git-workflow

    Squad branching model: dev-first workflow with insiders preview channel

    Also in 3 projects that use this

The file

We split this skill into the rules it gives an agent

3 rules. 0 are common, 1 is distinctive, and 2 are very specific to this project.

  • 0

    Common

    Most of the 13 edited versions we read keep these.

  • 1

    Distinctive

    This author's own choices. Worth a look.

  • 2

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Treat the type system as the primary correctness tool.

    line 14
  2. Very specific:

    Use a never exhaustiveness check on discriminated unions so adding a new variant fails the build:

    line 48
  3. Very specific:

    Use brands so you can't accidentally pass a UserId where an OrderId is expected:

    line 71

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

Treat the type system as the primary correctness tool. Tests verify behaviour; types prevent entire categories of bug from existing.

Hard rules

  1. tsconfig.json must have "strict": true and "noUncheckedIndexedAccess": true. Don't merge without these.
  2. No any in application code. unknown for external input, then narrow. Generics where the type depends on the caller.
  3. No type assertions (as Foo) unless paired with a runtime check that proves the assertion. Prefer satisfies.
  4. No enum unless required for interop with a non-TS consumer. Use string-literal unions: type Role = 'admin' | 'member'.
  5. No React.FC for components — use a typed props parameter. FC makes children implicit which causes confusion.

Patterns

Parse, don't validate

Convert untrusted data to a typed value at the system boundary, then trust the type everywhere downstream:

import { z } from "zod";

const UserSchema = z.object({
  email: z.string().email(),
  age: z.number().int().min(0).max(150),
});
type User = z.infer<typeof UserSchema>;

export function parseUser(raw: unknown): User {
  return UserSchema.parse(raw); // throws on invalid
}

Once you have a User, no other code needs to validate it again.

Exhaustive switches

Use a never exhaustiveness check on discriminated unions so adding a new variant fails the build:

type Event =
  | { kind: "created"; id: string }
  | { kind: "updated"; id: string; patch: Partial<User> }
  | { kind: "deleted"; id: string };

function describe(e: Event): string {
  switch (e.kind) {
    case "created": return `created ${e.id}`;
    case "updated": return `updated ${e.id}`;
    case "deleted": return `deleted ${e.id}`;
    default: {
      const _exhaustive: never = e;
      throw new Error(`unhandled event ${JSON.stringify(_exhaustive)}`);
    }
  }
}

Branded types for IDs

Use brands so you can't accidentally pass a UserId where an OrderId is expected:

type Brand<T, B> = T & { readonly __brand: B };
type UserId = Brand<string, "UserId">;
type OrderId = Brand<string, "OrderId">;

function userId(s: string): UserId { return s as UserId; }
function orderId(s: string): OrderId { return s as OrderId; }

Immutable updates

Mutation is forbidden. Always return new values:

// WRONG
function rename(user: User, name: string): User {
  user.name = name; // mutation!
  return user;
}

// RIGHT
function rename(user: Readonly<User>, name: string): User {
  return { ...user, name };
}

Errors as values for expected failures

Throwing is for bugs and unrecoverable states. For expected failures (validation, not-found, network), return a discriminated result:

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

What to flag in review

  • any anywhere except in // @ts-expect-error: <reason> comments.
  • as casts without a runtime guard.
  • Throwing inside a function whose signature claims it always returns.
  • Using .then instead of await (mixed styles in one function).
  • A Map or Set typed with <any, any>.
  • A discriminated-union switch without a never default.

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.