PartiallyRequired

Make some keys on a type required. Opposite of PartiallyOptional.

typescript
type PartiallyRequired<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>

Usage

typescript
type User = {
  name?: string
  email?: string
}
 
// Type where `email` is required, but `name` is still optional
type UserWithEmailRequired = PartiallyRequired<User, 'email'>
Created 28/10/21Updated 10/10/22
Found a mistake, or want to suggest an improvement? Source on GitHub here
and see edit history here