valid-state-types

Replace ad-hoc state flags with exhaustive discriminated unions in TypeScript-like type systems.

Updated Jul 17, 2017
One-click install
npx skills add https://github.com/luyi985/lyi-bash --skill valid-state-types
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: valid-state-types
Source: https://github.com/luyi985/lyi-bash/tree/main/ai/skills/valid-state-types
Command: npx skills add https://github.com/luyi985/lyi-bash --skill valid-state-types

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Types that allow invalid state combinations lead to bugs and hard-to-maintain code. This skill promotes designing types that enforce valid states from the start.

Core Features & Use Cases

  • Enforces valid state representations with discriminated unions
  • Encourages grouping of related fields to prevent partial states
  • Applies to models with interdependent statuses and complex state machines

Quick Start

Design discriminated unions to ensure only valid states can be represented in your type definitions

Frequently Asked Questions about valid-state-types

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

FAQPage Schema
How do I prevent invalid state combinations in TypeScript?

Use discriminated unions to prevent invalid state combinations. Group related fields and model exhaustive states to ensure your type definitions only represent valid, non-contradictory data structures.

What is a discriminated union and how does it enforce type safety?

A discriminated union enforces type safety by grouping related fields under a common literal property, allowing exhaustive checks to ensure only valid state combinations are represented in interdependent models.

How do I design TypeScript types for complex state machines with cascading statuses?

Design complex state machines by applying discriminated unions to group interdependent fields and cascading statuses, ensuring all states are exhaustive and preventing contradictory combinations across components.

When should I replace ad-hoc state flags with discriminated unions?

Replace ad-hoc state flags with discriminated unions when models contain interdependent fields or cascading statuses, ensuring all states are exhaustive and preventing partial or invalid combinations.

Does this approach to type design work without external dependencies?

Yes, designing valid state types works without external dependencies by relying purely on TypeScript-like type systems' discriminated unions and exhaustive checks to enforce valid state representations.