{"id":"8fe6feb3bfe60411","repo":"sindresorhus/is","slug":"expected-value-which-is-object-received-value-o","errorCode":null,"errorMessage":"Expected value which is `Object`, received value of type `${is(value)}`.","messagePattern":"Expected value which is `Object`, received value of type `(.+?)`\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"source/index.ts","lineNumber":1818,"sourceCode":"\t}\n}\n\nexport function assertNumber(value: unknown, message?: string): asserts value is number {\n\tif (!isNumber(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('number', value));\n\t}\n}\n\nexport function assertNumericString(value: unknown, message?: string): asserts value is `${number}` {\n\tif (!isNumericString(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('string with a number', value));\n\t}\n}\n\n// eslint-disable-next-line @typescript-eslint/no-restricted-types\nexport function assertObject(value: unknown, message?: string): asserts value is object {\n\tif (!isObject(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('Object', value));\n\t}\n}\n\nexport function assertObservable(value: unknown, message?: string): asserts value is ObservableLike {\n\tif (!isObservable(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('Observable', value));\n\t}\n}\n\nexport function assertOddInteger(value: number, message?: string): asserts value is number {\n\tif (!isOddInteger(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('odd integer', value));\n\t}\n}\n\nexport function assertPlainObject<Value = unknown>(value: unknown, message?: string): asserts value is Record<PropertyKey, Value> {\n\tif (!isPlainObject(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('plain object', value));","sourceCodeStart":1800,"sourceCodeEnd":1836,"githubUrl":"https://github.com/sindresorhus/is/blob/7821031c66cdeb7256a0feb2d506535f9e84fcaf/source/index.ts#L1800-L1836","documentation":"Thrown by `assert.object()` when the value is not of type `object` per `isObject` — which accepts plain objects, arrays, class instances, and functions, but rejects primitives and null. It exists so downstream code can safely access properties after the TypeScript narrowing `asserts value is object`.","triggerScenarios":"Calling `assert.object(value)` with null (typeof null is 'object' but isObject excludes it), undefined, a string, number, boolean, or symbol. Frequently hit when JSON.parse returns a scalar or when an optional field is absent.","commonSituations":"Deserialized API responses where the body is null or a bare string instead of an object; accessing a missing nested config key and asserting on undefined; a function returning null on failure instead of throwing.","solutions":["Check for null/undefined before asserting: the value is likely absent, not mistyped — fix the producer to always return an object or handle the missing case.","If you specifically need a plain object (not arrays/functions), use `assert.plainObject()` for a stricter check.","Inspect the reported received type in the message to locate which caller passed a primitive.","Validate JSON payloads at the trust boundary with a schema before deeper assertions."],"exampleFix":"// before\nconst config = JSON.parse(raw); // raw = 'null'\nassert.object(config); // throws: received 'null'\n// after\nconst config = JSON.parse(raw) ?? {};\nassert.object(config);","handlingStrategy":"type-guard","validationCode":"if (typeof value !== 'object' || value === null) {\n  throw new TypeError(`Expected object, got ${value === null ? 'null' : typeof value}`);\n}","typeGuard":"function isObject(value: unknown): value is object {\n  return (typeof value === 'object' && value !== null) || typeof value === 'function';\n}","tryCatchPattern":"try {\n  ow(value, ow.object);\n} catch (error) {\n  if (error instanceof ArgumentError) {\n    throw new TypeError(`Expected an object argument: ${error.message}`);\n  }\n  throw error;\n}","preventionTips":["typeof null === 'object' — always pair the typeof check with a null check","JSON.parse can return primitives (numbers, strings, null); validate the parsed shape before use","Optional chaining can yield undefined where an object was expected — check before passing along","Don't assume API responses are objects; validate at the boundary"],"tags":["type-check","assertion","null-check","runtime-validation"],"analyzedSha":"7821031c66cdeb7256a0feb2d506535f9e84fcaf","analyzedAt":"2026-07-31T18:34:06.268Z","schemaVersion":2}