principle-type-system-discipline

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

Updated Mar 27, 2026
One-click install
npx skills add https://github.com/gmackie/agent-skills --skill principle-type-system-discipline-gmackie
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: principle-type-system-discipline
Source: https://github.com/gmackie/agent-skills/tree/main/skills/principle-type-system-discipline
Command: npx skills add https://github.com/gmackie/agent-skills --skill principle-type-system-discipline-gmackie

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Weak type modeling lets contradictory states compile, hides unhandled variants, and pushes preventable failures to runtime. This Skill guides you to use the type checker as a proof assistant so invalid states, mismatched primitives, and missing cases are caught at compile time. ## Core Features & Use Cases - Sum Type Modeling: Replace bags of optional fields with discriminated unions, enums with payloads, or sealed classes so illegal combinations cannot be constructed. - Branded Primitives & Boundary Parsing: Distinguish semantic types like UserId from OrderId, and parse external data (JSON, RPC payloads, env vars) into typed models at every boundary. - Exhaustiveness & Schema Derivation: Enforce compiler-checked exhaustive matching and derive types from authoritative schemas like OpenAPI specs or protobuf definitions. - Use Case: While reviewing a TypeScript function that accepts { completed: boolean; completedAt?: Date }, apply this Skill to remodel it as { kind: 'open' } | { kind: 'done'; at: Date }, eliminating the meaningless completed: true with no date state. ## Quick Start Review this function signature and its types, and refactor them so illegal states are unrepresentable and all variants are exhaustively handled.

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 state as discriminated unions instead of optional field bags. For example, use `{ kind: 'open' } | { kind: 'done'; at: Date }` rather than `{ completed: boolean; completedAt?: Date }`, so contradictory combinations cannot compile.

How to enforce exhaustive matching on union types?▼

Use your language's exhaustiveness idiom: a `never`-typed binding in TypeScript, unannotated `match` in Rust, `-Wincomplete-patterns` in Haskell, or sealed-class matching in Kotlin. The compiler then fails when a new variant is added without handling.

Does this type discipline apply to languages other than TypeScript?▼

Yes, the patterns apply to any statically-typed language. It covers newtypes in Rust, opaque types in Swift, value classes in Kotlin, phantom types in Haskell, and ADTs in Haskell and OCaml.

When should I avoid strengthening a type further?▼

Strengthen a type only where partiality appears, such as a runtime assertion or null check. If nothing would otherwise panic, keep the plain type, since extra precision costs reuse and ceremony without buying safety.

Why are type casts and assertions considered risky?▼

Casts and assertion functions bypass the compiler's proof, turning checkable facts into runtime crashes. Instead, validate and narrow at the boundary or refine the model so the compiler can prove the fact.