Formatting rules for TypeScript conditional types. Use when writing complex conditional types to ensure debuggable, maintainable formatting with proper alignment.
Applies formatting rules for TypeScript conditional types to ensure debuggable, maintainable alignment.
/plugin marketplace add jasonkuhrt/claude-marketplace/plugin install typescript@jasonkuhrtThis skill inherits all available tools. When active, it can use any tool Claude has access to.
Enable commenting out individual cases without breaking syntax (useful for debugging).
Use for mutually exclusive top-level cases:
: at end of line for each case? symbols vertically within each caseUse when conditions are inherently nested (one inside another):
? and : symbols at each level// ✅ GOOD - FLAT pattern for mutually exclusive cases
// Each top-level case can be commented out safely
type Result<$T> = $T extends string ? 'string'
: $T extends number ? 'number'
// $T extends boolean ? 'boolean' : // ← Can comment out
: $T extends undefined ? 'undefined'
: 'unknown' // ← Final else, aligned
// ✅ GOOD - FLAT pattern with inner ternary
type LengthSlow<$S, $Acc> = $S extends `${string}${string}${string}${string}${infer __r__}`
? string extends __r__ // Inner ternary (nested logic)
? number
: LengthSlow<__r__, [...$Acc, 0, 0, 0, 0]> // ← : at end
: $S extends `${string}${string}${string}${infer __r__}` // ← Back to base
? string extends __r__ ? number
: [...$Acc, 0, 0, 0]['length'] // ← : at end
: $Acc['length'] // ← Final else
// ✅ GOOD - NESTED pattern (inherent logic requires it)
type DeepCheck<$S> = $S extends `${infer __c__}${infer __rest__}` ? string extends __rest__ ? number
: __rest__ extends '' ? 1
: __rest__ extends `${infer __c2__}${infer __r2__}` ? string extends __r2__ ? number
: __r2__ extends '' ? 2
: never
: never
: 0
// ❌ BAD - Misaligned flat pattern
type Bad<$T> = $T extends string ? 'string' // ← Alignment lost
: $T extends number ? 'number' // ← Alignment lost
: 'unknown'
// ❌ BAD - Using nested when flat would work
type Bad2<$T> = $T extends string ? 'string'
: $T extends number ? 'number' // ← Unnecessary nesting
: $T extends boolean ? 'boolean'
: 'unknown'
//dprint-ignore before long conditional types to preserve alignment? and : for readabilityThis skill should be used when the user asks about libraries, frameworks, API references, or needs code examples. Activates for setup questions, code generation involving libraries, or mentions of specific frameworks like React, Vue, Next.js, Prisma, Supabase, etc.