i had an object which contained a combination of numbers and strings, however, all properties in objects are strings. so i was looping an object and i only wanted to assign the properties that were numbers not string, i found thought i could just use isNaN so this is how my script looked like:
let val = false;
if(this.checkAll){
val = true;
}
for(let checkQuestionId in this.factoryQuestionSearch) {
if(!isNaN(checkQuestionId)) this.checkQuestionIds[checkQuestionId]=val;
}
thats when i got this errro:
Typescript Error
Argument of type 'string' is not assignable to parameter of type 'number'.
../pages/search/search.ts
so to solve it, all i had to do is change the code to:
let val = false;
if(this.checkAll){
val = true;
}
let temp:any;
for(let checkQuestionId in this.factoryQuestionSearch) {
temp = checkQuestionId.toString();
Number(temp);
if( !isNaN(temp)) this.checkQuestionIds[checkQuestionId]=val;
}
as you can see, i added a temp variable and change the temp variable to a string with toString()
Ionic Framework: 3.2.1 Ionic App Scripts: 1.3.7 Angular Core: 4.1.0 Angular Compiler CLI: 4.1.0 Node: 7.7.3 OS Platform: Windows 10 Navigator Platform: Win32