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/22Updated 10/10/22
Found a mistake, or want to suggest an improvement? Edit on GitHub here
and see edit history here