branded-types

Apply branded nominal typing with validated constructors to TypeScript values.

Updated Feb 22, 2026
One-click install
npx skills add https://github.com/JustinRoderick/skills --skill branded-types-justinroderick
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: branded-types
Source: https://github.com/JustinRoderick/skills/tree/main/.agents/skills/branded-types
Command: npx skills add https://github.com/JustinRoderick/skills --skill branded-types-justinroderick

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill prevents accidental mixing of structurally identical TypeScript values such as UserId, PostId, Email, and unit-specific numbers by adding compile-time nominal safety with zero runtime overhead.

Core Features & Use Cases

  • Defines a recommended branded type pattern using a shared unique symbol for clean, reusable type aliases.
  • Teaches validated constructor functions so unsafe casts stay confined to one place.
  • Covers practical use cases including type-safe IDs, validated strings, unit values, tokens, and integrations with tools like Zod, Drizzle, and Prisma.
  • Helps developers avoid common mistakes such as runtime brand checks, duplicate brand names, and over-branding.
  • Supports advanced patterns like composing multiple brands and unwrapping branded base types.

Quick Start

Ask the assistant to convert plain TypeScript string and number aliases into branded types with validated constructors and safe usage guidance.

Frequently Asked Questions about branded-types

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prevent TypeScript from mixing up structurally identical IDs like UserId and PostId?

TypeScript mixes structurally identical IDs because its structural type system treats them as interchangeable. Branded types solve this by adding compile-time nominal safety with zero runtime overhead, making distinct ID types impossible to mix up.

What's the best way to create validated string types like Email in TypeScript?

Validated string types are best created using branded types with constructor functions. This confines unsafe type assertions to a single validation point, ensuring invalid strings fail at the constructor level before reaching your application logic.

Does branded nominal typing work with Zod and Drizzle?

Branded nominal typing integrates directly with Zod and Drizzle. You can apply brand assertions within Zod schemas and map branded IDs to Drizzle columns, ensuring end-to-end type safety from database queries to API responses.

When should I avoid using branded types in a TypeScript codebase?

You should avoid branded types when over-branding simple values, using runtime brand checks instead of compile-time assertions, or creating duplicate brand names. Over-branding adds unnecessary complexity without meaningful safety benefits.

Can I compose multiple branded types together for advanced TypeScript safety?

Branded types support advanced composition by combining multiple brands and unwrapping branded base types. This allows you to layer different safety constraints, such as marking a value as both validated and unit-specific.

How do I convert plain TypeScript string and number aliases into branded types?

Convert plain TypeScript aliases by defining a shared Brand utility with a unique symbol, applying it to your base types, and creating validated constructor functions to enforce safe instantiation. This provides compile-time nominal typing and prevents accidental mixing.