{"id":"7699f12c6c6e6a9d","repo":"sindresorhus/is","slug":"expected-value-which-is-empty-object-received-v","errorCode":null,"errorMessage":"Expected value which is `empty object`, received value of type `${is(value)}`.","messagePattern":"Expected value which is `empty object`, received value of type `(.+?)`\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"source/index.ts","lineNumber":1568,"sourceCode":"\t\tthrow new TypeError(message ?? typeErrorMessage('T', instance));\n\t}\n}\n\nexport function assertEmptyArray(value: unknown, message?: string): asserts value is never[] {\n\tif (!isEmptyArray(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('empty array', value));\n\t}\n}\n\nexport function assertEmptyMap(value: unknown, message?: string): asserts value is Map<never, never> {\n\tif (!isEmptyMap(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('empty map', value));\n\t}\n}\n\nexport function assertEmptyObject<Key extends keyof any = string>(value: unknown, message?: string): asserts value is Record<Key, never> {\n\tif (!isEmptyObject(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('empty object', value));\n\t}\n}\n\nexport function assertEmptySet(value: unknown, message?: string): asserts value is Set<never> {\n\tif (!isEmptySet(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('empty set', value));\n\t}\n}\n\nexport function assertEmptyString(value: unknown, message?: string): asserts value is '' {\n\tif (!isEmptyString(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('empty string', value));\n\t}\n}\n\nexport function assertEmptyStringOrWhitespace(value: unknown, message?: string): asserts value is '' | Whitespace {\n\tif (!isEmptyStringOrWhitespace(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('empty string or whitespace', value));","sourceCodeStart":1550,"sourceCodeEnd":1586,"githubUrl":"https://github.com/sindresorhus/is/blob/7821031c66cdeb7256a0feb2d506535f9e84fcaf/source/index.ts#L1550-L1586","documentation":"Thrown by `assertEmptyObject` (source/index.ts:1566) when the value is not a plain object with zero enumerable own keys. The library checks both that the value is a plain object and that `Object.keys(value).length === 0`; anything else — a non-object, a class instance, or an object with properties — fails and throws a TypeError with the detected type from `is(value)`.","triggerScenarios":"Calling `assert.emptyObject(value)` with an object that has at least one enumerable key, with an array, null, a class instance, or any non-plain-object value.","commonSituations":"Asserting an options/config object was left empty; verifying an API response body is `{}`; surprises from objects with only symbol keys or non-enumerable properties (which still count as empty since only enumerable string keys are checked); accidentally passing `[]` or `null` instead of `{}`.","solutions":["Pass a plain `{}` object — arrays, null, and class instances are rejected regardless of contents","If keys are expected, use `assert.nonEmptyObject(value)` or `assert.plainObject(value)` instead","Delete or omit stray properties before the assertion if empty state is the invariant","Use the boolean form `is.emptyObject(value)` when failure should not throw"],"exampleFix":"// before\nassert.emptyObject({debug: false}); // has a key, throws\n// after\nassert.emptyObject({});","handlingStrategy":"type-guard","validationCode":"if (is.plainObject(value) && Object.keys(value).length === 0) {\n  assert.emptyObject(value);\n}","typeGuard":"function isEmptyObject(value: unknown): value is Record<string, never> {\n  return is.plainObject(value) && Object.keys(value).length === 0;\n}","tryCatchPattern":"try {\n  assert.emptyObject(value);\n} catch (error) {\n  if (error instanceof TypeError) {\n    // not an empty plain object — arrays, Maps, class instances all fail here\n  } else throw error;\n}","preventionTips":["Note that emptyObject requires a plain object — arrays, Maps and Sets are not objects for this check","Symbol keys may not count as 'keys' depending on implementation; check the library's definition of empty","Use is.emptyObject(value) as a boolean pre-check instead of catching the assert"],"tags":["type-assertion","runtime-validation","object","typescript"],"analyzedSha":"7821031c66cdeb7256a0feb2d506535f9e84fcaf","analyzedAt":"2026-07-31T18:34:06.268Z","schemaVersion":2}