Skip to content

Instantly share code, notes, and snippets.

@dewey92
Last active October 19, 2018 21:03
Show Gist options
  • Select an option

  • Save dewey92/5403e7d95e40850a5e161ce2273439fb to your computer and use it in GitHub Desktop.

Select an option

Save dewey92/5403e7d95e40850a5e161ce2273439fb to your computer and use it in GitHub Desktop.
TS Array Lookup
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