Real World Example

A Team Checklist for TypeScript Codebases

This is roughly what code review guidelines look like at product companies using TypeScript (Vercel, Razorpay, Atlassian):

AreaRule
Configstrict + noUncheckedIndexedAccess; tsc --noEmit, ESLint and Prettier in CI
Data from outsidevalidated with a schema at the boundary, types inferred from schemas
anybanned by lint; use unknown and narrow
Assertionsas and ! need a comment explaining why they are safe
Domain modellingdiscriminated unions for states, branded types for IDs and money
ErrorsResult types for expected failures, custom error classes for the rest
Exportsexplicit return types on public functions; import type for types
Suppressions@ts-expect-error with a ticket, never @ts-ignore

Putting It Together

Example

A small module written following the checklist: schema-free but validated input, branded ID, discriminated result, no any, explicit exported types.

declare const brand: unique symbol;
export type Sku = string & { readonly [brand]: "Sku" };
export type StockResult =
  | { kind: "ok"; sku: Sku; left: number }
  | { kind: "insufficient"; sku: Sku; available: number }
  | { kind: "unknown_sku"; input: string };

const SKU_RE = /^SKU-\d{3}$/;
const inventory = new Map<string, number>([["SKU-101", 5], ["SKU-202", 0]]);

export function parseSku(input: string): Sku | null {
  return SKU_RE.test(input) ? (input as Sku) : null;
}

export function reserve(input: string, qty: number): StockResult {
  const sku = parseSku(input);
  const available = sku === null ? undefined : inventory.get(sku);
  if (sku === null || available === undefined) return { kind: "unknown_sku", input };
  if (qty > available) return { kind: "insufficient", sku, available };
  inventory.set(sku, available - qty);
  return { kind: "ok", sku, left: available - qty };
}

for (const [sku, qty] of [["SKU-101", 2], ["SKU-202", 1], ["sku-1", 1], ["SKU-101", 9]] as const) {
  const r = reserve(sku, qty);
  switch (r.kind) {
    case "ok": console.log(`${r.sku}: reserved ${qty}, ${r.left} left`); break;
    case "insufficient": console.log(`${r.sku}: only ${r.available} available`); break;
    case "unknown_sku": console.log(`"${r.input}" is not a valid SKU`); break;
  }
}

Output

SKU-101: reserved 2, 3 left
SKU-202: only 0 available
"sku-1" is not a valid SKU
SKU-101: only 3 available