principle-type-system-discipline

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

1|Updated Aug 26, 2026
One-click install
npx skills add https://github.com/edivad1999/stuc-stack --skill principle-type-system-discipline-edivad1999
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: principle-type-system-discipline
Source: https://github.com/edivad1999/stuc-stack/tree/main/skills/principle-type-system-discipline
Command: npx skills add https://github.com/edivad1999/stuc-stack --skill principle-type-system-discipline-edivad1999

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Codebases accumulate runtime failures that the compiler could have prevented: contradictory field combinations, interchangeable primitive identifiers, unchecked casts, and non-exhaustive matches. This Skill provides a set of type system design patterns that shift those failures from runtime to compile time in any statically-typed language. ## Core Features & Use Cases - Illegal State Elimination: Model variants as sum types (sealed classes in Kotlin, discriminated unions in TypeScript, enums with payloads in Rust) instead of bags of optional fields. - Semantic Primitive Branding: Distinguish types like UserId and OrderId using value classes, newtypes, opaque types, or branded intersections so they cannot be swapped. - Boundary Parsing and Exhaustiveness: Parse untyped external data (JSON, RPC payloads, CLI args) at boundaries and enforce compiler-checked exhaustive matching on sum types. - Use Case: When reviewing a Kotlin data class with isComplete: Boolean and completedAt: Instant?, apply this Skill to refactor it into a sealed interface with Open and Done variants so contradictory states no longer compile. ## Quick Start Apply the type system discipline principle to review this function signature and refactor any types that admit illegal states.

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 Kotlin?▼

Model variants as sealed classes or sealed interfaces instead of a class with optional fields. For example, replace isComplete plus nullable completedAt with a sealed interface having Open and Done(at: Instant) variants so contradictory combinations cannot compile.

How to prevent mixing up string IDs like UserId and OrderId?▼

Brand semantic primitives so they are not interchangeable: use @JvmInline value class in Kotlin, newtypes in Rust, opaque types in Swift, or branded intersections in TypeScript. Validate once at creation and trust the type downstream.

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

Yes, the patterns apply to any statically-typed language. It covers discriminated unions in TypeScript, enums with payloads in Rust and Swift, ADTs in Haskell and OCaml, with language-specific skills like kotlin-best-practices grounding the syntax.

When should I avoid strengthening a type further?▼

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

Why are casts and non-null assertions considered hazards?▼

Casts, as, !!, and unsafe coercions bypass the compiler's proof, turning a fact it could not verify into a potential runtime crash. The guidance is to validate, narrow, or refine the model at the boundary instead of lying to the type system.