Type alias IsUnion<T, U>

IsUnion<T, U>: T extends unknown
    ? [U] extends [T]
        ? false
        : true
    : false

Check if type is union type.

Type Parameters

  • T
  • U extends T = T

Example

const isUnion: IsUnion<"123" | "456"> = true