principle-type-system-discipline

Applies type system patterns to make illegal states unrepresentable in statically-typed code.

Updated Aug 28, 2026
One-click install
npx skills add https://github.com/jeremybrasher/grokbot-skills --skill principle-type-system-discipline-jeremybrasher
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: principle-type-system-discipline
Source: https://github.com/jeremybrasher/grokbot-skills/tree/main/collections/pstack/skills/principle-type-system-discipline
Command: npx skills add https://github.com/jeremybrasher/grokbot-skills --skill principle-type-system-discipline-jeremybrasher

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Codebases in statically-typed languages often model state as bags of optional fields, rely on unchecked casts, and duplicate hand-written types that drift from authoritative schemas, producing runtime failures the compiler could have caught. ## Core Features & Use Cases - Illegal-state elimination: Model variants as sum types (discriminated unions, enums with payloads, sealed classes) so contradictory field combinations cannot compile. - Boundary parsing and branding: Parse external data (JSON, RPC payloads, env vars) into typed models at boundaries and brand semantic primitives like UserId versus OrderId. - Exhaustiveness and schema derivation: Enforce compiler-checked exhaustive matching and derive types from protobuf, OpenAPI, GraphQL, or migration schemas instead of hand-rolling parallel types. - Use Case: While reviewing a TypeScript function signature with { completed: boolean; completedAt?: Date }, apply the skill to remodel it as { kind: 'open' } | { kind: 'done'; at: Date } so invalid states stop compiling. ## Quick Start Ask the agent to review this function signature and apply type system discipline to make illegal states unrepresentable.

Frequently Asked Questions about principle-type-system-discipline

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

FAQPage Schema
How do I make illegal states unrepresentable in TypeScript?▼

Model variants as discriminated unions instead of optional field bags. For example, replace { completed: boolean; completedAt?: Date } with { kind: 'open' } | { kind: 'done'; at: Date } so contradictory combinations cannot compile.

How to enforce exhaustive switch matching on union types?▼

Use the idiom your language provides: a never-typed binding in TypeScript, an unannotated match in Rust, -Wincomplete-patterns in Haskell, or sealed-class exhaustiveness in Kotlin. The compiler then fails when a new variant is added without a handler.

Does this apply to languages other than TypeScript?▼

Yes, the patterns apply to any statically-typed language. It covers Rust enums with payloads, Swift and Kotlin sealed types, Scala sealed classes, and Haskell or OCaml ADTs, with language-specific idioms named for each.

When should I brand primitive types like UserId?▼

Brand primitives when two values share an underlying type but mean different things, such as UserId versus OrderId. Use newtypes in Rust, opaque types in Swift, value classes in Kotlin, or branded intersections in TypeScript, validating once at creation.

When should I not strengthen a type further?▼

Strengthen a type only where partiality actually appears, such as a runtime assertion or a this-should-never-happen throw. If nothing would otherwise panic, keep the plain type; the goal is totality, not maximum precision.