Typescript Utility types: Omit

실리콘·2022년 4월 20일
0

typescript

목록 보기
2/2

We define types using either type keyword or interface etc.

But sometimes we want to use a type, and conveninetly a type of similar properties already exist.

That is when we use Omit<main type| 'exclude property1', ...>

example

interface Product {
  id: number;
  name: string;
  price: number;
  brand: string;
  stock: number;
}

type shoppingItem = Omit<Product, "stock">;

const apple: Omit<Product, "stock"> = {
  id: 1,
  name: "red apple",
  price: 1000,
  brand: "del"
};
 
profile
software engineer

0개의 댓글