TypeScript: error TS2802: Type 'Set<string>' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher
You iterate a Set/Map/generator with an old compile target (ES5) where for...of/spread aren't natively supported.
error TS2802: Type 'Set<string>' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher.can only be iterated through when using the '--downlevelIteration' flagTS2802 downlevelIterationTS2569: Type 'Map<string, number>' is not an array type or a string type. Use compiler option '--downlevelIteration' to allow iterating of iterators. Meaning
Set "target": "es2015" (or higher, ideally es2020+), or enable downlevelIteration: true. Modern setups should target ES2020/ES2022; check lib includes es2015+.
Common causes
target: "es5"- Old tsconfig templates
libmissing es2015+- Spread of Set/Map/iterators
- for...of over iterables
⚡ Quick fix
"target": "ES2020"in tsconfig- Or
"downlevelIteration": true - Ensure
"lib": ["ES2020", "DOM"]
Detailed fix by platform
TypeScript
{ "compilerOptions": { "target": "ES2020", "lib": ["ES2020", "DOM"] } }
How to diagnose
- target — ES5?
- lib — es2015+?
- Flag — downlevelIteration?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- Cannot find module './App.vue' or its corresponding type declarations TypeScript: error TS2307: Cannot find module './App.vue' or its corresponding type declarations.
- TS17004: Cannot use JSX unless the '--jsx' flag is provided TypeScript: error TS17004: Cannot use JSX unless the '--jsx' flag is provided.
- TS2304 TS2304: Cannot find name 'x'.
Most viewed in TypeScript
Other ways to find it
Where this error sits
Origin: On your device. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 5 Nov 2026