Skip to content

Instantly share code, notes, and snippets.

@forivall
Created July 23, 2026 02:59
Show Gist options
  • Select an option

  • Save forivall/e50ce6c90c11723c695233beefc1417d to your computer and use it in GitHub Desktop.

Select an option

Save forivall/e50ce6c90c11723c695233beefc1417d to your computer and use it in GitHub Desktop.
export type MutuallyExclusive<T> = T &
(
| {
[K in keyof T]: K extends `only${string}`
? { [_ in K]: true } & {
[_ in Extract<Exclude<keyof T, K>, `only${string}`>]?: never;
}
: never;
}[keyof T]
| { [K in Extract<keyof T, `only${string}`>]?: false }
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment