【问题标题】:Type 'IterableIterator<[number, any]>' is not an array type or a string type类型 'IterableIterator<[number, any]>' 不是数组类型或字符串类型
【发布时间】:2019-11-29 13:11:48
【问题描述】:

我正在使用 ionic 4 构建应用程序。虽然我的应用程序在浏览器上运行良好,但是当我构建 android 平台时,它给了我这条线的错误

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

我的打字稿版本是 3.7.2

错误是

Type 'IterableIterator' 不是数组类型或 字符串类型。使用编译器选项“--downlevelIteration”来允许迭代器的迭代。

【问题讨论】:

    标签: typescript ionic4


    【解决方案1】:

    我通过在 tsconfig.josn 文件的 compilerOptions 中添加 "downlevelIteration": true 解决了这个问题。注意我的目标是 es2015

    【讨论】:

      【解决方案2】:

      我遇到了类似的问题,地图和循环最终出错

      public lastviewed = new Map<string, object>();
      
      for (const [key, value] of this.lastviewed.entries()) { //didnt work
          console.log(" Key : ", key, " Val : ", value);
      }
      

      导致错误:类型 'IterableIterator' 不是数组类型或字符串类型。使用编译器选项“--downlevelIteration” 在 tsconfig 中进行更改之前,我将循环从 entries 更改为 forEach,这对我来说很有效

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

      感谢thefourtheye的回答

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-08-19
        • 2019-11-21
        • 2022-11-28
        • 1970-01-01
        • 1970-01-01
        • 2021-11-05
        • 2021-12-18
        • 2022-01-02
        相关资源
        最近更新 更多