Skip to content

Instantly share code, notes, and snippets.

@devgioele
Last active April 18, 2023 12:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devgioele/de1e6776dfe5ec2b6333e09c28667cc1 to your computer and use it in GitHub Desktop.
Save devgioele/de1e6776dfe5ec2b6333e09c28667cc1 to your computer and use it in GitHub Desktop.
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