alleneubank avatar

Typescript Best Practices

Type-first TypeScript idioms covering discriminated unions, branded types, Zod runtime validation, and type-fest utilities.

skills.sh installs
2.9K
GitHub stars
49
last updated
Jul 14, 2026
View on GitHub

Own this skill? Claim it

What it does

  • Covers language-specific TypeScript and JavaScript idioms for .ts, .tsx, .js files, and tsconfig.json
  • Includes patterns for discriminated unions, branded primitives, const assertions, and exhaustive never switches
  • Enforces schema-first validation with Zod, using parse at trust boundaries and safeParse for user input
  • Designed for React work alongside react-best-practices, which covers component, hook, and effect patterns

Install

$ npx -y skills add alleneubank/claude-code --skill typescript-best-practices -y

Installs into .agents/skills for every agent it finds here, and .claude/skills for Claude Code.

Files

TypeScript Best Practices

Follows type-first, functional, and error handling patterns from CLAUDE.md. This skill covers language-specific idioms only.

Pair with React Best Practices

When working with React components (.tsx, .jsx files or @react imports), always load react-best-practices alongside this skill. This skill covers TypeScript fundamentals; React-specific patterns (effects, hooks, refs, component design) are in the dedicated React skill.

Make Illegal States Unrepresentable

Use the type system to prevent invalid states at compile time.

Discriminated unions for mutually exclusive states:

// Good: only valid combinations possible
type RequestState<T> =
  | { status: 'idle' }
  | { status: 'loading' }
  | { status: 'success'; data: T }
  | { status: 'error'; error: Error };

// Bad: allows invalid combinations like { loading: true, error: Error }
type RequestState<T> = {
  loading: boolean;
  data?: T;
  error?: Error;
};

Branded types for domain primitives:

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

Details

Repository
github.com/alleneubank/claude-code
Categories
Frontend & UI Code, Testing & QA, Code Review & Quality

More from alleneubank/claude-code

All 8

Similar to Typescript Best Practices

More Frontend & UI Code