{"record":{"id":"496aba346bb5e282","repo":"microsoft/TypeScript","slug":"object-is-not-iterable","errorCode":null,"errorMessage":"Object is not iterable.","messagePattern":"Object is not iterable\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/compiler/factory/emitHelpers.ts","lineNumber":1047,"sourceCode":"};\r\n\r\n// ES2015 Destructuring Helpers\r\n\r\nconst valuesHelper: UnscopedEmitHelper = {\r\n    name: \"typescript:values\",\r\n    importName: \"__values\",\r\n    scoped: false,\r\n    text: `\r\n            var __values = (this && this.__values) || function(o) {\r\n                var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\r\n                if (m) return m.call(o);\r\n                if (o && typeof o.length === \"number\") return {\r\n                    next: function () {\r\n                        if (o && i >= o.length) o = void 0;\r\n                        return { value: o && o[i++], done: !o };\r\n                    }\r\n                };\r\n                throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\r\n            };`,\r\n};\r\n\r\n// ES2015 Generator Helpers\r\n\r\n// The __generator helper is used by down-level transformations to emulate the runtime\r\n// semantics of an ES2015 generator function. When called, this helper returns an\r\n// object that implements the Iterator protocol, in that it has `next`, `return`, and\r\n// `throw` methods that step through the generator when invoked.\r\n//\r\n// parameters:\r\n//  @param thisArg  The value to use as the `this` binding for the transformed generator body.\r\n//  @param body     A function that acts as the transformed generator body.\r\n//\r\n// variables:\r\n//  _       Persistent state for the generator that is shared between the helper and the\r\n//          generator body. The state object has the following members:\r\n//            sent() - A method that returns or throws the current completion value.\r","sourceCodeStart":1029,"sourceCodeEnd":1065,"githubUrl":"https://github.com/microsoft/TypeScript/blob/b465fdbfe175304d9b977da137b2c178ae1091d3/src/compiler/factory/emitHelpers.ts#L1029-L1065","documentation":"`__values` downlevels for-of/spread. If the value has neither Symbol.iterator nor a numeric `.length`, and `Symbol.iterator` *does* exist on the runtime, it throws \"Object is not iterable.\" — i.e. the runtime supports iteration but the value isn't iterable.","triggerScenarios":"for-of (or spread/destructuring) over null, undefined, a plain object without an iterator, or any non-iterable non-array-like value.","commonSituations":"Iterating an object literal expecting entries; a function returning null where an iterable was expected; spreading a Map without calling .values()/.entries().","solutions":["Ensure the value is iterable (Array, Map, Set, generator, etc.) before iterating.","Add a null/iterable guard around the loop.","For plain objects use Object.entries/keys/values instead of for-of on the object."],"exampleFix":"// before\nconst obj = { a: 1 };\nfor (const x of obj) { }   // throws \"Object is not iterable.\"\n\n// after\nfor (const x of Object.entries(obj)) { }\n// or guard:\nif (obj && obj[Symbol.iterator]) for (const x of obj) { }","handlingStrategy":"type-guard","validationCode":"function assertIterable(v: unknown): void {\n  if (v == null || (typeof (v as any)[Symbol.iterator] !== \"function\" && typeof (v as any).length !== \"number\")) {\n    throw new TypeError(\"Object is not iterable.\");\n  }\n}","typeGuard":"function isIterable<T>(v: unknown): v is Iterable<T> {\n  return v != null && typeof (v as any)[Symbol.iterator] === \"function\";\n}","tryCatchPattern":null,"preventionTips":["Guard for-of loops when the source can be null/undefined.","Use Object.entries/keys/values for plain objects instead of for-of.","Type the source as Iterable<T> so the compiler catches misuse."],"tags":["iteration","runtime","emit-helpers"],"backgroundTag":null,"analyzedSha":"b465fdbfe175304d9b977da137b2c178ae1091d3","analyzedAt":"2026-08-12T05:38:42.698Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}