Objects 16 exercises
Problem

Exclude a Property from an Interface

Here we have an addProduct function which takes in productInfo, typed as Product.


interface Product {
id: number;
name: string;
price: number;
description: string;
}
const addProduct = (productInfo: Product) => {
// Do something with the productInfo
};

There are

Loading exercise

Transcript

00:00 In this exercise, we have an add product function which takes in a product info, which is typed as product, product, product, product, where we have an interface product at the top, which has ID number, name string, price number, and description string. Now, at the bottom, we have some example usage, and we can see that the example usage is different from the way that we've specced out as product

00:19 or add product, where we're not expecting to pass in the ID at any point. Down the bottom here, we have TS expect error over the ID property, indicating that you're not supposed to pass in an ID here. So we want to find a type here that has all of the properties of product without the ID.

00:39 So we want to grab all of them. There is a type helper for this, which is the opposite of pick that we've seen before, and I'll let you figure it out by yourself. Good luck.