ExactlyOne type

A discriminated union that enforces exactly one key from All.

Each variant requires one key and marks all other keys as ?: never, so fresh object literals that specify more than one operation are rejected at compile time.

type ExactlyOne<All> = {
  [K in keyof All]: { [P in K]: All[P] } & {
    [P in Exclude<keyof All, K>]?: never
  }
}[keyof All]