Objects 16 exercises
Problem

Excluding Fields from a TypeScript Type

Here we have a function updateProduct that takes two arguments: an id, and a productInfo object derived from the Product type, excluding the id field.


interface Product {
id: number;
name: string;
price: number;
description: string;
}
const updateProduct = (id: number, pr

Loading exercise

Transcript

00:00 In this exercise, we have an update product function which takes in an ID and a product info which omits the ID from the product. So in here, we should only have name, price, and description. But there's an interesting wrinkle here, which is with an update, sometimes we only want to update one property, maybe two properties at a time.

00:19 We don't need to pass in all of the properties for that product. So down here, we've got some test cases that are saying we should be able to update just the name, just the price, description. We should be able to update the name and the price if we want to, and name and description if we want to.

00:33 So your job is to try to work out a way that we can describe that inside this product info type here. So we still want to omit the ID. We don't want that because we're passing in the ID as the first parameter into update product. But we also want to make it all optional.

00:50 And there is a type helper that can help you do it. Good luck.