PartiallyOptional

Make some keys on a type optional. Opposite of PartiallyRequired.

typescript
          type PartiallyOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>
        

Usage

typescript
          type User = {
  name: string
  email: string
}
 
// Type where `email` is optional, but `name` is still required
type UserWithEmailOptional = PartiallyOptional<User, 'email'>
        
Created 10/10/22 • Updated 10/10/22