state-machines

Implement type-safe state machines with discriminated unions and a status property.

3|Updated Dec 30, 2025
One-click install
npx skills add https://github.com/guicheffer/devorch-cli --skill state-machines-guicheffer
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: state-machines
Source: https://github.com/guicheffer/devorch-cli/tree/main/templates/skills/state-management/state-machines
Command: npx skills add https://github.com/guicheffer/devorch-cli --skill state-machines-guicheffer

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill provides a robust pattern for managing complex application states, preventing impossible states and ensuring predictable transitions, especially for asynchronous operations and multi-step processes.

Core Features & Use Cases

  • Type-Safe State Management: Uses discriminated unions with a 'status' property for guaranteed type safety.
  • Predictable Transitions: Enforces explicit state changes, reducing bugs and improving testability.
  • Async Operations: Ideal for managing loading, success, and error states of API calls.
  • Multi-Step Forms: Manages complex user flows like wizards or checkout processes.
  • Use Case: When building a user registration form with multiple steps (personal info, address, payment), this Skill ensures that you can only proceed to the next step when the current one is valid, and clearly displays loading or error states during submission.

Quick Start

Implement a type-safe state machine for managing asynchronous data loading using discriminated unions and a 'status' property.

Frequently Asked Questions about state-machines

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

FAQPage Schema
How do I manage complex async state in TypeScript without hitting impossible states?

You can prevent impossible states in TypeScript by implementing type-safe state machines with discriminated unions. This pattern uses a 'status' property to enforce explicit transitions, ensuring predictable behavior during asynchronous operations and multi-step processes.

What is the best way to handle multi-step form state with Zustand?

Handling multi-step form state with Zustand is best achieved using discriminated unions to enforce explicit transitions. This approach guarantees step validation before proceeding and clearly displays loading or error states during submission, all without requiring middleware.

How do discriminated unions work for state management in TypeScript?

Discriminated unions work for state management by using a shared 'status' property to narrow types, guaranteeing type safety. This mechanism ensures only valid properties are accessible for each specific state, preventing impossible combinations and allowing helper functions to safely extract data.

Do I need middleware to build a state machine in Zustand?

You do not need middleware to build a state machine in Zustand. This approach leverages the core Zustand store alongside discriminated unions and helper functions to enforce explicit state transitions, ensuring predictable behavior without adding extra dependencies.

How to prevent invalid state transitions during async API calls in TypeScript?

To prevent invalid transitions during async API calls, implement type-safe state machines using discriminated unions. This pattern enforces explicit state changes for loading, success, and error statuses, ensuring safe property extraction and predictable application behavior.