November 2018
Beginner
502 pages
10h 22m
English
This ensures we return a value in all branches of a function if the return type isn't void.
Let's see this in action with an example:
getTotal(discount: number): number { if (discount) { const priceWithoutDiscount = this.product.unitPrice * this.quantity; const discountAmount = priceWithoutDiscount * discount; return priceWithoutDiscount - discountAmount; } else { // We forgot about this branch! }}
tsc orderDetail
Read now
Unlock full access