TS2802: Type can only be iterated through when using the '--downlevelIteration' flag TypeScript Origin: On your device OSI layer 7 · Application Last updated 5 Nov 2026

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.

Exact message you may see 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.
Seen on: TypeScript

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
  • lib missing es2015+
  • Spread of Set/Map/iterators
  • for...of over iterables

⚡ Quick fix

  1. "target": "ES2020" in tsconfig
  2. Or "downlevelIteration": true
  3. Ensure "lib": ["ES2020", "DOM"]

Detailed fix by platform

TypeScript

  1. { "compilerOptions": { "target": "ES2020", "lib": ["ES2020", "DOM"] } }

How to diagnose

  1. target — ES5?
  2. lib — es2015+?
  3. 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:

Where this error sits

Origin: On your device. Errors that are often confused with or caused by this one (click to open):

Cannot find module './App.vue' or its corresponding type declarations — TypeScript: error TS2307: Cannot find module './App.vue' or its corresponding type declarations. (Vue)Cannot find module '.…TS17004: Cannot use JSX unless the '--jsx' flag is provided — TypeScript: error TS17004: Cannot use JSX unless the '--jsx' flag is provided. (TypeScript)TS17004: Cannot use J…TS2304 — TS2304: Cannot find name 'x'. (Node.js)TS2304TS2688: Cannot find type definition file for 'x' — TypeScript: error TS2688: Cannot find type definition file for 'node'. (TypeScript)TS2688: Cannot find t…TS2792: Cannot find module — did you mean to set the 'moduleResolution' option to 'nodenext' — TypeScript: error TS2792: Cannot find module 'x'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? (TypeScript)TS2792: Cannot find m…TS5083: Cannot read file tsconfig.json / extends not found — TypeScript: error TS5083: Cannot read file '/app/tsconfig.json'. / error TS6053: File 'tsconfig.base.json' not found (TypeScript)TS5083: Cannot read f…TS5095: Option 'bundler' can only be used when 'module' is set to 'preserve' or 'es2015' or later — TypeScript: error TS5095 (TypeScript)TS5095: Option 'bundl…TS6059: File is not under 'rootDir' — TypeScript: error TS6059: File '/app/shared/util.ts' is not under 'rootDir' '/app/src'. 'rootDir' is expected to contain all source files. (TypeScript)TS6059: File is not u…TS2802: T…

Explore the map of this error Full error map →

🧠 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.