Skip to content

Instantly share code, notes, and snippets.

@devgioele
Last active April 18, 2023 12:27
Partial and Required helpers
/**
* A version of `Partial` that makes only the given keys of `T` optional.
*/
export type PartialPick<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>
/**
* A version of `Partial` that makes all the not specified keys of `T` optional.
*/
export type PartialOmit<T, K extends keyof T> = Pick<T, K> & Partial<Omit<T, K>>
/**
* A version of `Required` that makes only the given keys of `T` required.
*/
export type RequiredPick<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>
/**
* A version of `Required` that makes all the not specified keys of `T` required.
*/
export type RequiredOmit<T, K extends keyof T> = Pick<T, K> & Required<Omit<T, K>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment