principle-type-system-discipline

Applies type system patterns to eliminate illegal states and unhandled variants in statically-typed code.

Updated Sep 18, 2026
One-click install
npx skills add https://github.com/fern-works/greenline --skill principle-type-system-discipline-fern-works
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: principle-type-system-discipline
Source: https://github.com/fern-works/greenline/tree/main/corpus/upstream/pstack/f5bdd6826fd0a0d9cbc4347134c3a74a200b9d9d/principle-type-system-discipline
Command: npx skills add https://github.com/fern-works/greenline --skill principle-type-system-discipline-fern-works

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Codebases in statically-typed languages often let contradictory states compile, mix up semantically different primitives, and miss cases when new variants are added, 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) instead of bags of optional fields. - Boundary Parsing and Branding: Parse external data (JSON, RPC payloads, env vars) into typed models and brand semantic primitives like UserId versus OrderId. - Exhaustiveness and Totality: Enforce compiler-checked exhaustive matching and prefer total functions over runtime assertions. - Use Case: When reviewing a function signature like { completed: boolean; completedAt?: Date }, apply this Skill to remodel it as { kind: 'open' } | { kind: 'done'; at: Date } so meaningless combinations cannot compile. ## Quick Start Ask the agent to review this type definition or function signature using the type system discipline and point out any illegal states it permits.

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 objects with optional fields. For example, replace `{ completed: boolean; completedAt?: Date }` with `{ kind: 'open' } | { kind: 'done'; at: Date }` so contradictory combinations cannot compile.

How to prevent mixing up IDs that share the same primitive type?▼

Brand semantic primitives so UserId and OrderId are not interchangeable even though both are strings. Use newtypes in Rust, opaque types in Swift, value classes in Kotlin, or branded intersections in TypeScript, validating once at creation.

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

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

When should I strengthen a type versus keep it simple?▼

Strengthen a type only where partiality appears, such as a runtime assertion, null check, or a throw marking a case the type is too weak to track. If nothing would otherwise panic, keep the plain type rather than pursuing precision for its own sake.

Why are type casts and assertions considered hazardous?▼

Casts, unsafe coercions, and assertion functions bypass the compiler's proof, creating latent runtime crashes. Instead, validate and narrow at the boundary where untyped data enters, or refine the model so the compiler can prove the fact.