The below code gives the following error on
"[i]" in "if (i == ingredients[i])"
error:
element implicitly has an 'any' type because index expression is not of type 'number'
code:
let ingredients = ["ham","onion","tomato"];
let sandwichhas = function(ingredients:string[]){
for(let i of ingredients){
if (i == ingredients[i]){
return true;
}
}
}
if (snd("tomato") && snd("onion")){
console.log("Sandwich has tomatos and onions")
}else {
console.log("Sandwich has no tomatos and onions")
}
And in the if statement below there's an error saying:
Argument of type '"tomato"' is not assignable to parameter of type 'string[]'.
Argument of type '"onion"' is not assignable to parameter of type 'string[]'.
What is the workaround for this?