TypeScript: Duplicate identifier 'IteratorResult'

后端 未结 10 1829
无人共我
无人共我 2020-12-15 01:59

I\'m trying to compile via tsc--which I\'ve installed globally--and I\'m getting an error:

~/AppData/R         


        
相关标签:
10条回答
  • 2020-12-15 02:51

    I was getting the is error in my angular 8 App and couldn't resolve the issue after trying all suggestions made here including the accepted answer. I had to look at a previous angular 6 App that compiled without errors and realised that I could just skip the library check by including

    "skipLibCheck": true

    to the tsconfig.json file. With the fact that my App is running well without problems, I decided to take this approach. Here is the complete configuartion of my tsconfig.json file

    { "compileOnSave": false,
      "compilerOptions": {
      "baseUrl": "./",
      "outDir": "./dist/out-tsc",
      "sourceMap": true,
      "declaration": false,
      "downlevelIteration": true,
      "experimentalDecorators": true,
      "module": "esnext",
      "moduleResolution": "node",
      "importHelpers": true,
      "target": "es2015",
      "typeRoots": [
      "node_modules/@types"
      ],
      "lib": [
        "es2018",
        "dom"
      ],
      "skipLibCheck": true
      },
      "angularCompilerOptions": {
      "fullTemplateTypeCheck": true,
      "strictInjectionParameters": true
      }
    }
    

    There were no more errors after this configuration. Note: That doesn't mean that the problem is solved but at least it allowed me to skip the bug that was causing the error. Due to the fact that my App is running as expected I just considered this error irrelevant at this moment.

    0 讨论(0)
  • 2020-12-15 02:54

    Just upgrade @types/node in devDependencies of your Angular project:

     npm i --save-dev @types/node
    

    *** Do not change anything in node_modules ***

    0 讨论(0)
  • 2020-12-15 03:00

    As @Muhammad bin Yusrat said in his comment, run npm i @types/node@latest (npm i @types/node doesn't work !!) if you have just updated angular to 9. That worked for me.

    It also got rid of another ionic 5 console error after running ionic serve-> 'refused to load image 'http:localhost:8100/favicon.ico' because it violates the following Content Security Policy .....' (see below).

    Another 'IteratorResult' error was caused by "Spread Types" Error. See Typescript: Spread types may only be created from object types. Basically somewhere in your code you have used a spread operator like this return { id: doc.payload.id, ...doc.payload.data() }; and you have to change it to this return { id: doc.payload.id, ...doc.payload.data() as {} }; ie add as {}

    0 讨论(0)
  • 2020-12-15 03:04

    Found an issue on GitHub - https://github.com/microsoft/TypeScript/issues/32333 which was related. @rbuckton suggested upgrading @types/node. It worked for me.

    0 讨论(0)
提交回复
热议问题