Skip to content

Instantly share code, notes, and snippets.

@apotox
Created January 26, 2022 10:47
Show Gist options
  • Save apotox/78c5704340d80a428f29bf6dacafe3fe to your computer and use it in GitHub Desktop.
Save apotox/78c5704340d80a428f29bf6dacafe3fe to your computer and use it in GitHub Desktop.
typescript: make some properties required from an optional props
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