Tagged Unions

🌐Community
by marius-townhouse · vlatest · Repository

This skill creates complex, named relationships between tokens, streamlining data organization and enhancing semantic understanding for your AI projects.

Install on your platform

We auto-selected Claude Code based on this skill’s supported platforms.

1

Run in terminal (recommended)

terminal
claude mcp add tagged-unions npx -- -y @trustedskills/tagged-unions
2

Or manually add to ~/.claude/settings.json

~/.claude/settings.json
{
  "mcpServers": {
    "tagged-unions": {
      "command": "npx",
      "args": [
        "-y",
        "@trustedskills/tagged-unions"
      ]
    }
  }
}

Requires Claude Code (claude CLI). Run claude --version to verify your install.

About This Skill

What it does

The tagged-unions skill allows AI agents to understand and generate TypeScript code that utilizes tagged unions. Tagged unions, also known as discriminated unions, are a powerful type system feature in TypeScript enabling more robust and type-safe handling of different data types within a single variable. This skill enables the agent to reason about and produce code leveraging this pattern for improved clarity and error prevention.

When to use it

  • Handling Variant Data: When an AI agent needs to process data that can be one of several distinct, typed forms (e.g., success/failure responses from an API).
  • Type-Safe State Management: For creating state machines or complex component logic where the type of state changes dynamically.
  • Improving Code Readability: When refactoring existing code to make it more understandable and maintainable by leveraging tagged unions for clearer data representation.
  • Generating Data Structures: To create custom data structures that represent a union of different types, ensuring type safety during operations.

Key capabilities

  • Understanding tagged union syntax in TypeScript.
  • Generating code utilizing discriminated unions.
  • Reasoning about the benefits of using tagged unions for type safety.
  • Applying tagged unions to various scenarios (e.g., API responses, state management).

Example prompts

  • "Generate a TypeScript function that handles either a 'Success' or 'Error' result using a tagged union."
  • "Show me how to implement a simple state machine in TypeScript with tagged unions."
  • “Write a type for an API response which can be either a User object or an ErrorMessage object.”

Tips & gotchas

This skill assumes basic familiarity with TypeScript syntax and concepts. While tagged unions improve type safety, they can increase code complexity if overused; consider the trade-offs when applying this pattern.

Tags

🛡️

TrustedSkills Verification

Unlike other registries that point to live repositories, TrustedSkills pins every skill to a verified commit hash. This protects you from malicious updates — what you install today is exactly what was reviewed and verified.

Security Audits

Gen Agent Trust HubPass
SocketPass
SnykPass

Details

Version
vlatest
License
Author
marius-townhouse
Installs
4

🌐 Community

Passed automated security scans.