TypeScript: Duplicate identifier 'IteratorResult' TypeScript: Duplicate identifier 'IteratorResult' typescript typescript

TypeScript: Duplicate identifier 'IteratorResult'


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


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.


I suspect it is because your include section:

"include": [    "app/**/*.ts",    "app/**/*.tsx",    "test/**/*.ts",    "test/**/*.tsx",    "node_modules/@types/**/*.d.ts",    "./types/**/*.d.ts"  ]

You usually don't need to explicitly include *.d.ts files. And probably never declaration files from other libraries (or node types).

tsconfig's "exclude" section excludes everything under "node_modules" by default (among other things). When you add "node_modules/@types/**/*.d.ts" you override that exclude and tsc tries to include them, but those types are already declared.

Check Typescript docs on tsconfig.json, it explains the "typeRoots", "files" and "include"/"exclude" config options in detail.