typescript-patterns

A set of modern TypeScript coding guidelines. TypeScript is JavaScript with optional compile-time checks for values and object shapes.

In plain words
What is it for?
Writing, reviewing, and refactoring Node.js, React, and full-stack TypeScript with strict settings, safer types, generics, unions, and build tools.
Why use it?
It encourages the compiler to catch mistakes and discourages unsafe shortcuts such as any, unchecked casts, and non-null assertions.

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/chandrudp29/skillhub/typescript-patterns
Any agent
npx skills add chandrudp29/skillhub --skill typescript-patterns
Clone the repo
git clone --depth 1 https://github.com/chandrudp29/skillhub

Made for: Claude Code, Codex.

Per session 30 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 763 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.00030 $0.00763
Opus 5 $0.00015 $0.00381
Sonnet 5 $0.00006 $0.00153
Haiku 4.5 $0.00003 $0.00076

Measured 2d ago against content hash 104b2e86698e, 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 2d 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.

skills/typescript-patterns/SKILL.md · 102 lines

How it starts

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

When to Use

Apply when writing, reviewing, or refactoring any TypeScript code. Works for Node.js backends, React frontends, and full-stack projects.

Core Rules

  • Always use strict: true in tsconfig — never disable it to fix an error
  • Prefer type for unions and intersections, interface for object shapes that extend
  • Use unknown over any at boundaries; narrow with type guards before use
  • Never use as casts to silence errors — fix the type instead
  • Avoid ! non-null assertions unless you've verified the value exists

Type Design

// Discriminated unions over boolean flags
type Result<T> =
  | { success: true; data: T }
  | { success: false; error: string };

// Utility types — use them, don't reinvent
type UserPreview = Pick<User, 'id' | 'name' | 'email'>;
type PartialConfig = Partial<Config>;
type ReadonlyUser = Readonly<User>;

// Branded types for semantic safety
type UserId = string & { readonly __brand: 'UserId' };
type EmailAddress = string & { readonly __brand: 'EmailAddress' };

// Const assertions for literal inference
const ROLES = ['admin', 'editor', 'viewer'] as const;
type Role = typeof ROLES[number]; // 'admin' | 'editor' | 'viewer'

Generics

// Constrain generics — never leave them open if you can help it
function first<T>(arr: readonly T[]): T | undefined {
  return arr[0];
}

// Conditional types for inference
type Awaited<T> = T extends Promise<infer U> ? U : T;

// Template literal types for string APIs
type EventName = `on${Capitalize<string>}`;

Runtime Safety

// Type guards at system boundaries
function isUser(value: unknown): value is User {
  return (
    typeof value === 'object' &&
    value !== null &&
    'id' in value &&
    typeof (value as User).id === 'string'
  );
}

// Zod for schema validation at API boundaries
import { z } from 'zod';
const UserSchema = z.object({ id: z.string(), email: z.string().email() });
type User = z.infer<typeof UserSchema>;

Read the full file on GitHub · 102 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. 2d ago First seen · 102 lines · 30 tokens per session scan A 104b2e86698e

Subscribe to this mod's changes

typescript-patterns is a skill published in the GitHub repository chandrudp29/skillhub (13 stars, last pushed 2mo ago), licensed MIT. It adds 30 tokens to every session and 763 once invoked, about $0.0002 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.