control-union-distribution

Control union distribution in TypeScript conditional types with tuple wrappers.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Conditional types in TypeScript distribute over unions by default, often producing surprising results. This skill explains how to control distribution so you can prevent it when undesired and enable it when needed.

Core Features & Use Cases

  • Understand distributive behavior of conditional types over unions.
  • Prevent distribution using one-tuple wrappers; force distribution with bare conditions.
  • Handle edge cases involving boolean and never, including recursive types that may misbehave.

Quick Start

Demonstrate how to prevent distribution over unions by wrapping the type in a one-tuple in a TypeScript example.

Frequently Asked Questions about control-union-distribution

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

FAQPage Schema
Why do my TypeScript conditional types distribute over unions unexpectedly?

TypeScript conditional types distribute over unions by default when the checked type is a bare type parameter, often producing surprising results that require explicit one-tuple wrappers to prevent.

How do I prevent union distribution in conditional types?

To prevent union distribution in conditional types, wrap the checked type in a one-tuple form within the conditional check, which stops TypeScript from treating bare union types as distributive.

How do I force union distribution in TypeScript conditional types?

To force union distribution in TypeScript conditional types, use bare type parameters without wrapping them in tuples, which triggers the default distributive behavior over the union members.

How do I handle boolean and never edge cases in TypeScript distributive conditional types?

Handle boolean and never edge cases in distributive conditional types by applying one-tuple wrappers to prevent unwanted distribution, ensuring recursive types do not misbehave during type-level evaluation.

What is the best way to control type distribution in advanced TypeScript type-level programming?

The best way to control type distribution in advanced TypeScript type-level programming is toggling between bare conditions to force distribution and one-tuple wrappers to prevent it, handling boolean and never edge cases safely.