Skip to content

Instantly share code, notes, and snippets.

@forivall
Created June 8, 2020 23:17
Show Gist options
  • Save forivall/886549956625e6e6f9f3b9a4430fb1aa to your computer and use it in GitHub Desktop.
Save forivall/886549956625e6e6f9f3b9a4430fb1aa to your computer and use it in GitHub Desktop.
Useful type for mutating unioned types
import type { UnionToIntersection } from 'ts-essentials';
export type UnionToBuildable<T> = {
-readonly [K in Extract<keyof UnionToIntersection<T>, keyof T>]: T[K];
} &
{
-readonly [K in Exclude<
keyof UnionToIntersection<T>,
keyof T
>]?: T extends { [_ in K]: infer U } ? U : never;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment