Created
January 26, 2022 10:47
-
-
Save apotox/78c5704340d80a428f29bf6dacafe3fe to your computer and use it in GitHub Desktop.
typescript: make some properties required from an optional props
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
type SomeRequired<T , TRequired extends keyof T> = T & Required<Pick<T,TRequired>> | |
//example | |
type TmpUser = { | |
photo?: string, | |
username?: string | |
} | |
type User = SomeRequired<TmpUser, 'username'> | |
user type will be like this /* | |
photo?: string, | |
username: string | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment