Created
July 15, 2023 15:12
-
-
Save viniazvd/1715725fc1f45fab3ac11d44d0ed7116 to your computer and use it in GitHub Desktop.
Optional.ts
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
/** | |
* 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