Created
June 8, 2020 23:17
-
-
Save forivall/886549956625e6e6f9f3b9a4430fb1aa to your computer and use it in GitHub Desktop.
Useful type for mutating unioned types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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