Type 'IterableIterator<[number, any]>' 不是数组类型也不是字符串类型
Type 'IterableIterator<[number, any]>' is not an array type or a string type
我正在使用 ionic 4 构建应用程序。虽然我的应用程序在浏览器上运行良好,但是当我构建 android 平台时,它给我这条线的错误
for (let [index, p] of this.cart.entries())
我的打字稿版本是 3.7.2
错误是
Type 'IterableIterator<[number, any]>' is not an array type or a
string type. Use compiler option '--downlevelIteration' to allow iterating of iterators.
我通过在 tsconfig.josn 文件中的 compilerOptions 中添加 "downlevelIteration": true 解决了这个问题。注意我的目标是 es2015
我有类似的问题是地图和循环以错误告终
public lastviewed = new Map<string, object>();
for (const [key, value] of this.lastviewed.entries()) { //didnt work
console.log(" Key : ", key, " Val : ", value);
}
导致错误:类型 'IterableIterator<[string, object]>' 不是数组类型或字符串类型。使用编译器选项“--downlevelIteration”
Intead 在 tsconfig 中更改我将循环从 entries 更改为 forEach 并且它对我有用
this.lastviewed.forEach((value: object, key: string) => {//worked
console.log("PRINTING : ", key, value);
});
感谢回答
我正在使用 ionic 4 构建应用程序。虽然我的应用程序在浏览器上运行良好,但是当我构建 android 平台时,它给我这条线的错误
for (let [index, p] of this.cart.entries())
我的打字稿版本是 3.7.2
错误是
Type 'IterableIterator<[number, any]>' is not an array type or a string type. Use compiler option '--downlevelIteration' to allow iterating of iterators.
我通过在 tsconfig.josn 文件中的 compilerOptions 中添加 "downlevelIteration": true 解决了这个问题。注意我的目标是 es2015
我有类似的问题是地图和循环以错误告终
public lastviewed = new Map<string, object>();
for (const [key, value] of this.lastviewed.entries()) { //didnt work
console.log(" Key : ", key, " Val : ", value);
}
导致错误:类型 'IterableIterator<[string, object]>' 不是数组类型或字符串类型。使用编译器选项“--downlevelIteration” Intead 在 tsconfig 中更改我将循环从 entries 更改为 forEach 并且它对我有用
this.lastviewed.forEach((value: object, key: string) => {//worked
console.log("PRINTING : ", key, value);
});
感谢