Last active
October 19, 2018 21:03
-
-
Save dewey92/5403e7d95e40850a5e161ce2273439fb to your computer and use it in GitHub Desktop.
TS Array Lookup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const getFinalPrice = (product: ProductModel) => | |
| product.price + product.tax; | |
| const getProductById = (products: ProductModel[], id: number) => | |
| products.find(product => product.id === id); | |
| const product = getProductById(productList, 1); | |
| const finalPrice = getFinalPrice(product); // <- ERROR | |
| // Argument of type 'ProductModel | undefined' is not assignable to parameter of type 'ProductModel'. | |
| // Type 'undefined' is not assignable to type 'ProductModel'. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment