tsentials-union

Encode compile-time-safe tagged discriminated unions for TypeScript service-layer outcomes.

49|Updated May 12, 2026
One-click install
npx skills add https://github.com/senrecep/tsentials --skill tsentials-union
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: tsentials-union
Source: https://github.com/senrecep/tsentials/tree/main/.well-known/agent-skills/tsentials-union
Command: npx skills add https://github.com/senrecep/tsentials --skill tsentials-union

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Union types let you represent multiple distinct outcomes, but developers often fall back to untyped object returns or unsafe casting, losing exhaustiveness and correctness guarantees.

Core Features & Use Cases

  • Tagged discriminated union: define outcomes like success, pending, and failed with compile-time-safe payloads.
  • Exhaustive pattern matching: use Union.match() so TypeScript flags missing cases.
  • Type guards and extraction: use Union.is() for narrowing and Union.get() to extract a specific branch value.

Quick Start

Ask your AI to rewrite your service return type to use Union<T> and refactor your response mapping with Union.match() for exhaustive handling.

Frequently Asked Questions about tsentials-union

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

FAQPage Schema
How do I model multiple API response outcomes with a type-safe discriminated union in TypeScript?

You can model multiple API response outcomes by defining a tagged discriminated union that assigns distinct payloads to specific tags like success and failed, ensuring compile-time safety and eliminating untyped object returns.

Why does TypeScript not catch missing branches when handling different service layer outcomes?

TypeScript misses missing branches when service layer outcomes lack a shared discriminating tag. Using a tagged discriminated union with exhaustive pattern matching via match() forces the compiler to flag unhandled cases.

How do I use exhaustive pattern matching to eliminate unsafe object returns in TypeScript?

Exhaustive pattern matching eliminates unsafe object returns by requiring a handler for every tagged union branch. Construct outcomes using Union.of() and dispatch them through Union.match() to ensure complete type coverage.

Can I use type guards to narrow specific failure and success branches in TypeScript domain modeling?

Yes, you can use type guards to narrow specific branches by applying Union.is() for narrowing and Union.get() to safely extract the structured payload from a targeted failure or success branch.

What is the best way to type multiple workflow states that carry different structured data in TypeScript?

The best way to type multiple workflow states carrying different structured data is encoding them in a compile-time-safe tagged discriminated union, allowing each branch to hold unique payload shapes safely.