Skip to content

Instantly share code, notes, and snippets.

@viniazvd
Created July 15, 2023 15:12
Show Gist options
  • Save viniazvd/1715725fc1f45fab3ac11d44d0ed7116 to your computer and use it in GitHub Desktop.
Save viniazvd/1715725fc1f45fab3ac11d44d0ed7116 to your computer and use it in GitHub Desktop.
Optional.ts
/**
* Make some property optional on type
*
* @example
* ```typescript
* type Post {
* id: string;
* name: string;
* email: string;
* }
*
* Optional<Post, 'id' | 'email'>
* ```
**/
export type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment