branded-types

Apply phantom branding patterns to create nominal types in TypeScript.

Updated Jul 17, 2017
One-click install
npx skills add https://github.com/luyi985/lyi-bash --skill branded-types-luyi985
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: branded-types
Source: https://github.com/luyi985/lyi-bash/tree/main/ai/skills/branded-types
Command: npx skills add https://github.com/luyi985/lyi-bash --skill branded-types-luyi985

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Semantic distinction for primitive values using branded types in TypeScript to prevent misuse and accidental mixing of semantically different values.

Core Features & Use Cases

  • Phantom branding patterns to create nominal types such as UserId, Identifier, or SanitizedString
  • Zero runtime overhead while enforcing strong compile-time safety across modules and libraries
  • Practical use cases include IDs, units, and validated strings to prevent accidental cross-usage

Quick Start

Create a branded type for a user ID after validating the input.

Frequently Asked Questions about branded-types

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

FAQPage Schema
How do I prevent accidental mixing of different ID types in TypeScript?▼

Branded types in TypeScript prevent accidental mixing by applying phantom branding patterns to primitives, creating nominal types like UserId. This enforces compile-time safety across modules with zero runtime overhead.

What is the best way to enforce semantic distinction for primitive values in TypeScript?▼

Semantic distinction for primitive values is enforced using branded types, creating reusable patterns for validated strings and identifiers. This prevents misuse without adding runtime overhead.

How do I create a validated string type that ensures type-level safety?▼

Create a branded type for validated strings by applying phantom branding after input validation. This ensures type-level safety, guaranteeing only properly sanitized values are assigned.

Can I use branded types to distinguish units of measurement in a frontend app?▼

Yes, branded types distinguish units of measurement and identifiers in frontend apps. They satisfy type-level safety across libraries, preventing accidental cross-usage of semantically different values.

Does branded typing add runtime overhead to TypeScript libraries?▼

No, branded types operate entirely at compile-time with zero runtime overhead. They enforce strong type-level safety across modules and libraries without impacting application performance.

When should I not use nominal typing for identifiers?▼

Nominal typing for identifiers is unnecessary when simple primitives suffice without semantic distinction. Avoid it if your codebase does not require strict compile-time safety or validated strings.