Solving the Never Type in TypeScript
Here we have a shoppingCart
object with an items
property initialized as an empty array:
const shoppingCart = { items: [],};
We are able to list the items in the shopping cart by logging shoppingCart.items
to the console. However, we have an error when trying to add items to th
Transcript
00:00 In this exercise we have a shopping cart const here where we have items is an empty array. We're console logging those items and then we are pushing some things to them. We're pushing an apple and a banana to them. But we're getting an interesting error here which is argument of type string is not assignable to parameter of type never.
00:19 Your job is to work out why this error is occurring and work out how we can perhaps add a type here to make this error go away.