Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type 'IterableIterator<[number, any]>' is not an array type or a string type

I am using ionic 4 to build an app. Whereas my app is working fine on browser but when I build android platform it is giving me error for this line

for (let [index, p] of this.cart.entries())

My typescript version is 3.7.2

The error is

Type 'IterableIterator<[number, any]>' is not an array type or a string type. Use compiler option '--downlevelIteration' to allow iterating of iterators.

like image 476
pratik jaiswal Avatar asked Nov 29 '19 13:11

pratik jaiswal


2 Answers

I solved it by adding "downlevelIteration": true, in compilerOptions inside tsconfig.josn file. Note my target was es2015

like image 122
pratik jaiswal Avatar answered Nov 16 '22 04:11

pratik jaiswal


I had similar issue following was the map and loop ended up in error

public lastviewed = new Map<string, object>();

for (const [key, value] of this.lastviewed.entries()) { //didnt work
    console.log(" Key : ", key, " Val : ", value);
}

resulted in Error : Type 'IterableIterator<[string, object]>' is not an array type or a string type. Use compiler option '--downlevelIteration' Intead of changing in tsconfig i changed loop from entries to forEach and it worked out for me

    this.lastviewed.forEach((value: object, key: string) => {//worked
        console.log("PRINTING : ", key, value);
    });

thanks to thefourtheye answer

like image 35
Parameshwar Avatar answered Nov 16 '22 04:11

Parameshwar