簡體   English   中英

發生打字錯誤。 類型'IterableIterator<any> ' 不是數組類型或字符串類型。)</any>

[英]Typscript error happening . Type 'IterableIterator<any>' is not an array type or a string type.)

嗨,我有一個 angular 項目,我有一個錯誤,我可以在 vss 代碼中看到。 不知道我該如何解決這個問題。

    Type 'IterableIterator<any>' is not an array type or a string type.
 Use compiler option '--downlevelIteration' to allow iterating of iterators.ts(2569)

這是代碼片段

  aggregator(data: HistogramDistribution[]) {
   data.forEach(
      item => {
       item.dateRange =  moment.utc(item.dateRange).local().format("YYYY-MM-DD").toString();
      }
    );
 
    return [...data
      .reduce((acc, o) => {
        
        const key = o.dateRange,
              group = acc.get(key)
        group ?
        (group.total += o.total, 
        group.delivered += o.delivered, 
        group.undeliverable += o.undeliverable,
        group.expired += o.expired,
        group.enroute += o.enroute) :
        acc.set(key, {...o, dateRange: key})
        return acc
      }, new Map)
      .values()
   ];
  }

我試圖在我的 tsconfig.json 中添加“downlevelIteration”:true。 但錯誤仍然存在。

{
  "compileOnSave": false,
  "compilerOptions": {
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "typeRoots": ["node_modules/@types"],
    "lib": ["es2017", "dom"],
    "downlevelIteration": true
  }
}

感謝您是否可以提供一些幫助。

謝謝你

tsconfig.json文件中將編譯目標更改為es6或更高版本將修復它

{
  "compilerOptions": {
    "target": "es2015"
  }
}

或者如果你想繼續使用舊版本,你可以像這樣啟用downLevelIteration

{
  "compilerOptions": {
    "target": "es2015",
    "downlevelIteration": true
   }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM