'TS7053: Element implicitly has an 'any' type
Sry for my stupid question, but i can`t search answer for my promlem. TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{ width: number; height: number; title: string; }'
let menu:{width:number; height:number; title:string} = {
width: 200,
height: 300,
title: 'My menu',
}
function multiplyNumeric(menu:{width:number; height: number; title: string}):void {
for (let k in menu){
if (typeof menu[k] === "number"){
menu[k] = Number(menu[k]) * 2;
}
}
}
multiplyNumeric(menu);
Solution 1:[1]
On your multiplyNumeric function the parameter 'menu' has invalid data type. You cannot set like that. From what i understand you want your menu parameter to be an object with three properties
{
width:number;
height: number;
title: string
}
You need to define an interface to do the job.
inteface menuObj {
width:number;
height: number;
title: string;
}
And then do something like this:
function multiplyNumeric(menu: menuObj)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Vasilis |
