TypeScript Version: 2.5.3
Code
enum Topping {
Cheese = 'cheese',
Olives = 'olives',
}
type Pizza = {
toppings: Topping[];
};
const pizza = {
toppings: [Topping.Cheese]
};
function calculateToppingPrice(topping: Topping): number {
// ... whatever
return 0;
}
let pizzaCost = 10;
for (let topping in pizza.toppings) {
// Argument of type 'string' is not assignable to parameter of type 'Topping'.
pizzaCost += calculateToppingPrice(topping);
}
Expected behavior:
The let topping in the for..in loop is of type Topping
Actual behavior:
The let topping in the for..in loop is of type string
I think you meant to use a for-of loop. Thanks JavaScript...
@DanielRosenwasser ughuyghuhguh.... thank you!
Most helpful comment
I think you meant to use a
for-ofloop. Thanks JavaScript...