typescript-patterns

typescript-patterns is a skill for Claude Code, Codex from kazdenc/builder-skills. It costs 62 tokens per session (2,464 once invoked), scanned A, original, MIT.

A guide to writing safer and clearer TypeScript code, the programming language that adds checking to JavaScript.

In plain words
What is it for?
Use it when creating, reviewing, or reorganising TypeScript with narrow types, reusable type rules, checked alternatives, safer errors, and module boundaries.
Why use it?
It helps catch mismatched data and other mistakes while code is being written instead of waiting for them to fail during use.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/kazdenc/builder-skills/typescript-patterns
Any agent
npx skills add kazdenc/builder-skills --skill typescript-patterns
Clone the repo
git clone --depth 1 https://github.com/kazdenc/builder-skills

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for typescript-patterns

README.md
[![agentmods](https://agentmods.dev/badge/skills/kazdenc/builder-skills/typescript-patterns.svg)](https://agentmods.dev/skills/kazdenc/builder-skills/typescript-patterns)
Your own site
<a href="https://agentmods.dev/skills/kazdenc/builder-skills/typescript-patterns"><img src="https://agentmods.dev/badge/skills/kazdenc/builder-skills/typescript-patterns.svg" alt="Measured on agentmods" height="20"></a>
Per session 62 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,464 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00062 $0.02464
Opus 5 $0.00031 $0.01232
Sonnet 5 $0.00012 $0.00493
Haiku 4.5 $0.00006 $0.00246

Measured 4d ago against content hash 66720319efda, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

typescript-patterns scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 4d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.claude/skills/dev/frameworks/typescript-patterns/SKILL.md · 283 lines

How it starts

The opening of the file, as written. The whole thing — 283 lines — stays where its author put it; the contents beside it link to each section on GitHub.

TypeScript Patterns

Apply these patterns when writing, reviewing, or refactoring TypeScript code. Prefer type safety over convenience. Catch errors at compile time, not runtime.

Type Design Principles

Default to the narrowest type that accurately represents the data. Widen only when you have a concrete reason.

Principle Do Don't
Narrow types status: "active" | "inactive" status: string
Branded types for IDs type UserId = string & { __brand: "UserId" } userId: string (mixable with any string)
Discriminated unions { kind: "circle"; radius: number } | { kind: "rect"; w: number; h: number } Type assertions to distinguish shapes
Readonly by default readonly items: Item[] Mutable arrays unless mutation is required
Explicit return types on public APIs function getUser(id: UserId): Promise<User> Inferred return types on exported functions

Branded Types

Use branded types to prevent accidental mixing of structurally identical values:

type UserId = string & { readonly __brand: unique symbol };
type OrderId = string & { readonly __brand: unique symbol };

function createUserId(id: string): UserId {
  return id as UserId;
}

function getOrder(orderId: OrderId): Order { /* ... */ }

// Compile error: UserId is not assignable to OrderId
getOrder(createUserId("abc"));

Generics

Use generics when a function or type operates on a value whose type the caller determines. Don't add generics speculatively — add them when you have two or more concrete use cases.

Constraining Generics

Always constrain generics to the narrowest interface they need:

// Good — constrained to what the function actually uses
function getProperty<T extends Record<string, unknown>, K extends keyof T>(obj: T, key: K): T[K] {
  return obj[key];
}

// Bad — unconstrained, anything goes
function getProperty<T>(obj: T, key: string): unknown { /* ... */ }

Common Generic Patterns

Read the full file on GitHub · 283 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 4d ago First seen · 283 lines · 62 tokens per session scan A 66720319efda

Subscribe to this mod's changes

typescript-patterns is a skill published in the GitHub repository kazdenc/builder-skills (44 stars, last pushed 5mo ago), licensed MIT. It adds 62 tokens to every session and 2,464 once invoked, about $0.0003 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories

client-setup

Create a vanilla tRPC client with createTRPCClient (), configure link chain with httpBatchLink/httpLink, dynamic headers for auth, transformer on links (not client constructor). Infer types with inferRouterInputs and inferRouterOutputs. AbortController signal support. TRPCClientError typing.

trpc/trpc · 63 tokens

adapter-express

Mount tRPC as Express middleware with createExpressMiddleware() from @trpc/server/adapters/express. Access Express req/res in createContext via CreateExpressContextOptions. Mount at a path prefix like app.use('/trpc', ...). Avoid global express.json() conflicting with tRPC body parsing for FormData.

trpc/trpc · 67 tokens

trpc-router

Entry point for all tRPC skills. Decision tree routing by task: initTRPC.create(), t.router(), t.procedure, createTRPCClient, adapters, subscriptions, React Query, Next.js, links, middleware, validators, error handling, caching, FormData.

trpc/trpc · 59 tokens

clone-website

Reverse-engineer and clone a website in one shot — extracts assets, CSS, and content section-by-section and proactively dispatches parallel builder agents in worktrees as it goes. Use this whenever the user wants to clone, replicate, rebuild, reverse-engineer, or copy any website. Also triggers on phrases like "make a…

yournextstore/yournextstore · 93 tokens

prettify

Iteratively improves the visual design of an existing page — making it more sophisticated, richer, and prettier — without redesigning from scratch. Works on any page or UI surface: landing pages, marketing pages, pricing, docs, dashboards, admin views, settings, modals, empty states, etc. Use when the user says…

yournextstore/yournextstore · 0 tokens

rebase-themes

Rebase all theme- branches onto main, resolving conflicts while preserving each theme's visual identity. Force-pushes directly to theme branches with backup tags. Run as a scheduled task or one-off.

yournextstore/yournextstore · 45 tokens