Partial
is another utility type that is available in TypeScript. Partial
makes all the properties of a type optional, which allows a property or certain properties to be updated.
Example
interface Product {
id: string,
name: string,
quantity: number
}
const cheddarCheese: Product = {
id: "4578989345589",
name: "Generic Cheddar Cheese",
quantity: 10
}
let updateQuantity: Partial<Product> = {}
updateQuantity.quantity = 8
console.log(cheddarCheese) //{id: "4578989345589", name: "Generic Cheddar Cheese", quantity: 8}