extract partial attributes of an object using typescript types

36 Views Asked by At

how to extract partial attributes of an object using typescript types? is it even possible?

export interface Product {
  brandName: string;
  modelNo: string;
  rate: number | null;
  someOtherProp1: string;
  someOtherProp2: string;

}


export interface OrderItem {
  modelNo: string;
  rate: number;
  qty: number;
}

const exampleProduct: Product = {
  brandName: "Example Brand",
  modelNo: "12345",
  rate: 100,
  someOtherProp1: "Some Value 1",
  someOtherProp2: "Some Value 2"
};



Then how can i create an instance of order item from product, i tried following which does not work:

const exampleOrderItem: OrderItem = {
  ...exampleProduct,
  qty: 10
};
0

There are 0 best solutions below