Hyperlinkv0.8.0-beta.28

Types

Types.IsUniontypeeffect/Types.ts:888
IsUnion<T>

Checks whether a type T is a union type.

When to use

Use to branch type-level logic depending on whether a type is a union.

Details

  • Compares [T] against [UnionToIntersection<T>]. If they differ, T must be a union.
  • Returns true if T is a union of two or more members.
  • Returns false for single types, never, or any.

Example (Detecting union types)

import type { Types } from "effect"

type Yes = Types.IsUnion<"a" | "b"> // true
type No = Types.IsUnion<string> // false
Source effect/Types.ts:8881 lines
export type IsUnion<T> = [T] extends [UnionToIntersection<T>] ? false : true