{"record":{"id":"6484ec62d363c772","repo":"microsoft/TypeScript","slug":"object-expected","errorCode":null,"errorMessage":"Object expected","messagePattern":"Object expected","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/compiler/factory/emitHelpers.ts","lineNumber":787,"sourceCode":"    importName: \"__esDecorate\",\r\n    scoped: false,\r\n    priority: 2,\r\n    text: `\r\n        var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {\r\n            function accept(f) { if (f !== void 0 && typeof f !== \"function\") throw new TypeError(\"Function expected\"); return f; }\r\n            var kind = contextIn.kind, key = kind === \"getter\" ? \"get\" : kind === \"setter\" ? \"set\" : \"value\";\r\n            var target = !descriptorIn && ctor ? contextIn[\"static\"] ? ctor : ctor.prototype : null;\r\n            var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});\r\n            var _, done = false;\r\n            for (var i = decorators.length - 1; i >= 0; i--) {\r\n                var context = {};\r\n                for (var p in contextIn) context[p] = p === \"access\" ? {} : contextIn[p];\r\n                for (var p in contextIn.access) context.access[p] = contextIn.access[p];\r\n                context.addInitializer = function (f) { if (done) throw new TypeError(\"Cannot add initializers after decoration has completed\"); extraInitializers.push(accept(f || null)); };\r\n                var result = (0, decorators[i])(kind === \"accessor\" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);\r\n                if (kind === \"accessor\") {\r\n                    if (result === void 0) continue;\r\n                    if (result === null || typeof result !== \"object\") throw new TypeError(\"Object expected\");\r\n                    if (_ = accept(result.get)) descriptor.get = _;\r\n                    if (_ = accept(result.set)) descriptor.set = _;\r\n                    if (_ = accept(result.init)) initializers.unshift(_);\r\n                }\r\n                else if (_ = accept(result)) {\r\n                    if (kind === \"field\") initializers.unshift(_);\r\n                    else descriptor[key] = _;\r\n                }\r\n            }\r\n            if (target) Object.defineProperty(target, contextIn.name, descriptor);\r\n            done = true;\r\n        };`,\r\n};\r\n\r\nconst runInitializersHelper: UnscopedEmitHelper = {\r\n    name: \"typescript:runInitializers\",\r\n    importName: \"__runInitializers\",\r\n    scoped: false,\r","sourceCodeStart":769,"sourceCodeEnd":805,"githubUrl":"https://github.com/microsoft/TypeScript/blob/b465fdbfe175304d9b977da137b2c178ae1091d3/src/compiler/factory/emitHelpers.ts#L769-L805","documentation":"For `accessor`-kind decorated elements, `__esDecorate` requires a non-undefined decorator return value to be an object (with optional get/set/init). Returning a primitive throws \"Object expected\".","triggerScenarios":"An accessor decorator returns a number, string, boolean, or any non-object value (other than undefined).","commonSituations":"Misunderstanding the accessor-decorator contract; reusing a method/field decorator on an accessor.","solutions":["Return `undefined` or an object `{ get?, set?, init? }` from accessor decorators.","Use a decorator specifically written for the accessor kind (check ctx.kind === \"accessor\").","Raise target to a runtime with native decorators to avoid the helper."],"exampleFix":"// before\nfunction acc(v, ctx) { return 42; }            // non-object -> \"Object expected\"\nclass A { @acc accessor x = 1; }\n\n// after\nfunction acc(v, ctx) { return { init: () => 2 }; }\nclass A { @acc accessor x = 1; }","handlingStrategy":"type-guard","validationCode":"function validateAccessorResult(v: unknown): void {\n  if (v !== undefined && (v === null || typeof v !== \"object\")) {\n    throw new TypeError(\"Accessor decorator must return undefined or an object.\");\n  }\n}","typeGuard":"function isAccessorDescriptor(v: unknown): v is { get?: Function; set?: Function; init?: Function } {\n  return v === undefined || (typeof v === \"object\" && v !== null);\n}","tryCatchPattern":null,"preventionTips":["Return undefined or { get?, set?, init? } from accessor decorators.","Branch on ctx.kind so the right shape is returned per kind."],"tags":["decorators","accessor","runtime","emit-helpers"],"backgroundTag":null,"analyzedSha":"b465fdbfe175304d9b977da137b2c178ae1091d3","analyzedAt":"2026-08-12T05:38:42.698Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}