principle-type-system-discipline

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

Updated Sep 2, 2026
One-click install
npx skills add https://github.com/jnyross/pstack-muse --skill principle-type-system-discipline-jnyross
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: principle-type-system-discipline
Source: https://github.com/jnyross/pstack-muse/tree/main/skills/principle-type-system-discipline
Command: npx skills add https://github.com/jnyross/pstack-muse --skill principle-type-system-discipline-jnyross

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Codebases in statically-typed languages often model state as bags of optional fields, rely on unsafe casts, and duplicate schema shapes by hand, letting the compiler accept programs that fail at runtime. This Skill provides a set of type design principles that push those failure modes from runtime into compile time. ## 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 untyped external data (JSON, RPC payloads, env vars) at boundaries and brand semantic primitives like UserId versus OrderId to prevent mix-ups. - Exhaustiveness and Schema Derivation: Enforce exhaustive matching so new variants break compilation, and derive types from authoritative schemas (protobuf, OpenAPI, GraphQL) instead of hand-rolled duplicates. - Use Case: When reviewing a TypeScript function signature like { completed: boolean; completedAt?: Date }, apply the Skill to remodel it as { kind: 'open' } | { kind: 'done'; at: Date }, removing the meaningless state where completed is true but completedAt is undefined. ## Quick Start Ask the AI to review your type definitions and function signatures using the type system discipline principles to find states the compiler should reject.

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 prevent mixing up primitive types like UserId and OrderId?

Brand semantic primitives so they are not interchangeable despite sharing an underlying type. Use branded intersections in TypeScript, newtypes in Rust, opaque types in Swift, or value classes in Kotlin, validating once at creation.

Does this approach work for languages other than TypeScript?

Yes, the principles apply to any statically-typed language. The Skill maps each pattern to language-specific idioms: enums with payloads in Rust and Swift, sealed classes in Kotlin and Scala, and ADTs in Haskell and OCaml.

When should I not strengthen 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 is casting with 'as' or 'any' considered a problem?

Casts and assertion functions bypass the compiler's proof, turning checkable facts into runtime crashes. The Skill directs you to trace each cast back to a boundary and validate or narrow there instead.