November 2018
Beginner
502 pages
10h 22m
English
The type information helps the TypeScript compiler catch bugs and typos before our users run into them. In code editors such as Visual Studio Code, a mistake is underlined in red immediately after the user has gone wrong. As an example, create a file called utils.js and paste in the following code, which calculates the total price on an order line:
function calculateTotalPrice(product, quantity, discount) { var priceWithoutDiscount = product.price * quantity; var discountAmount = priceWithoutDiscount * discount; return priceWithoutDiscount - discountAmount;}
There is a bug in the code that might be difficult for us to spot. If we open the file in Visual Studio Code, no errors are highlighted. If we change the ...
Read now
Unlock full access