-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterface.ts
More file actions
40 lines (32 loc) · 839 Bytes
/
interface.ts
File metadata and controls
40 lines (32 loc) · 839 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
interface DiscountCode {
code: string
percentage: number
}
interface ProductWithDiscountCode extends Product {
discountCodes: DiscountCode[]
}
type getTotal = (discount?: number) => number
interface OrderDetail {
product: Product
quantity: number
dateAdded?: Date
getTotal: getTotal
}
const table: ProductWithDiscountCode = {
name: "Table",
unitPrice: 500,
discountCodes: [
{ code: "SUMMER10", percentage: 0.1 },
{ code: "BFRI", percentage: 0.2 }
]
}
const tableOrder: OrderDetail = {
product: table,
quantity: 1,
getTotal(discount = 0) {
const priceWithoutDiscount = this.product.unitPrice * this.quantity
const discountAmount = priceWithoutDiscount * discount
return priceWithoutDiscount - discountAmount
}
}
tableOrder.getTotal() //?