exclusive-or-properties

Enforces mutually exclusive TypeScript properties at compile time using optional never types.

Updated Sep 5, 2026
One-click install
npx skills add https://github.com/pohlai88/afenda-xforge-v5 --skill exclusive-or-properties-pohlai88
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: exclusive-or-properties
Source: https://github.com/pohlai88/afenda-xforge-v5/tree/main/.agents/skills/exclusive-or-properties
Command: npx skills add https://github.com/pohlai88/afenda-xforge-v5 --skill exclusive-or-properties-pohlai88

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? TypeScript interfaces with all-optional properties allow invalid combinations—none, one, or many fields—forcing developers to write runtime validation that catches errors too late. This Skill shows how to model "exactly one of" constraints at the type level so invalid states become compile-time errors. ## Core Features & Use Cases - Optional Never Pattern: Build union types where each variant makes one property required and all others never, so the compiler rejects invalid combinations. - Reusable Helper Types: Apply generic XOR<A, B> and ExactlyOne<T> utility types to reduce repetition across your codebase. - Use Case: When designing a LoadConfig type that accepts a URL, file path, or raw content—but never more than one—this pattern makes { url, filePath } a compile error instead of a runtime exception. ## Quick Start Refactor my TypeScript interface so that exactly one of its source properties must be provided, using the optional never pattern.

Frequently Asked Questions about exclusive-or-properties

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

FAQPage Schema
How do I enforce exactly one property in a TypeScript type?

Use a union of object variants where each variant makes one property required and the others optional with type never. For example, `{ url: string; filePath?: never } | { url?: never; filePath: string }` ensures exactly one is present at compile time.

What is the optional never pattern in TypeScript?

The optional never pattern marks mutually exclusive properties as optional with type never, so providing them alongside a conflicting variant causes a compile error. It models exclusive-or constraints without runtime checks.

How do I write a generic XOR type in TypeScript?

Define `XOR<A, B>` as `(A & { [K in keyof B]?: never }) | (B & { [K in keyof A]?: never })`. For more than two options, use an `ExactlyOne<T>` mapped type that generates one variant per key with all other keys set to never.

When should I not use the XOR type pattern?

Avoid it when multiple properties can legitimately coexist, since the pattern forbids all combinations. It also adds verbosity for simple cases, so use helper types like XOR or ExactlyOne to keep definitions readable.

Why use type-level enforcement instead of runtime validation?

Type-level enforcement catches invalid property combinations at compile time, before code runs. Runtime validation only surfaces errors during execution, making bugs harder to detect and requiring extra test coverage.