Skip to content

Instantly share code, notes, and snippets.

@katsimoto
Last active June 23, 2022 01:21
Show Gist options
  • Save katsimoto/f5e3ee8a2c3a284effb2d9f1b8ccc045 to your computer and use it in GitHub Desktop.
Save katsimoto/f5e3ee8a2c3a284effb2d9f1b8ccc045 to your computer and use it in GitHub Desktop.
TypeScript Tools
// https://medium.com/javascript-in-plain-english/powerful-typescript-tools-e1c7875fbb71
type KeysToUnion<T> = keyof T;
type KeysToValue<T> = T[KeysToUnion<T>]
type KeysToTuple<T> = KeysToUnion<T>[]
type OmitPartial<T, K extends keyof T> = Omit<T, K> & {
[Key in K]?: T[Key]
}
type ReadonlyPartial<T> = {
readonly [K in keyof T]?: T[K]
}
type DeepReadonlyPartial<T> = {
readonly [K in keyof T]?:
T[K] extends object ? DeepReadonlyPartial<T[K]> : T[K]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment