Partial and Required
The Partial
type produces a new object type where all properties are optional, and Required
produces an object type where all properties are required.
The Partial<T>
specification is often used when working with a subset of an object's properties. In the example below, a simple updateUser
function allows a partial set of user properties to be updated.
We can combine Partial
and Required
to build a type where some keys are optional, and others are required. Suppose we want to store all color definitions properties in a single Color
interface: