{"id":"96e30b4cbcdf41c2","repo":"sindresorhus/is","slug":"expected-value-which-is-non-empty-object-receiv","errorCode":null,"errorMessage":"Expected value which is `non-empty object`, received value of type `${is(value)}`.","messagePattern":"Expected value which is `non-empty object`, received value of type `(.+?)`\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"source/index.ts","lineNumber":1755,"sourceCode":"\t\tthrow new TypeError(message ?? typeErrorMessage('Node.js Stream', value));\n\t}\n}\n\nexport function assertNonEmptyArray<T = unknown, Item = unknown>(value: T | Item[], message?: string): asserts value is [Item, ...Item[]] {\n\tif (!isNonEmptyArray(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('non-empty array', value));\n\t}\n}\n\nexport function assertNonEmptyMap<Key = unknown, Value = unknown>(value: unknown, message?: string): asserts value is Map<Key, Value> {\n\tif (!isNonEmptyMap(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('non-empty map', value));\n\t}\n}\n\nexport function assertNonEmptyObject<Key extends keyof any = string, Value = unknown>(value: unknown, message?: string): asserts value is Record<Key, Value> {\n\tif (!isNonEmptyObject(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('non-empty object', value));\n\t}\n}\n\nexport function assertNonEmptySet<T = unknown>(value: unknown, message?: string): asserts value is Set<T> {\n\tif (!isNonEmptySet(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('non-empty set', value));\n\t}\n}\n\nexport function assertNonEmptyString(value: unknown, message?: string): asserts value is string {\n\tif (!isNonEmptyString(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('non-empty string', value));\n\t}\n}\n\nexport function assertNonEmptyStringAndNotWhitespace(value: unknown, message?: string): asserts value is string {\n\tif (!isNonEmptyStringAndNotWhitespace(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('non-empty string and not whitespace', value));","sourceCodeStart":1737,"sourceCodeEnd":1773,"githubUrl":"https://github.com/sindresorhus/is/blob/7821031c66cdeb7256a0feb2d506535f9e84fcaf/source/index.ts#L1737-L1773","documentation":"Thrown by `assertNonEmptyObject()` (source/index.ts:1753) when the value fails `isNonEmptyObject()` — it must be a plain-ish object with at least one own enumerable key. Arrays, Maps, Sets, `null`, and `{}` all fail. On success TypeScript narrows the value to `Record<Key, Value>`.","triggerScenarios":"Calling `assert.nonEmptyObject(value)` with `{}`, `null`, an array, a Map/Set (their entries are not enumerable keys), or an object whose properties are all non-enumerable or symbol-keyed.","commonSituations":"Empty request bodies or config objects (`{}` from a missing JSON file or unset env-driven config); passing a Map thinking its size counts; destructured options objects defaulting to `{}`.","solutions":["Verify the object actually has keys — e.g. ensure the config file loaded and parsed correctly before asserting.","If the value may legitimately be empty, branch on `is.nonEmptyObject(value)` instead of asserting.","If holding a Map or Set, use `assert.nonEmptyMap`/`assert.nonEmptySet` instead — those are distinct checks.","Remember only own enumerable string keys count; spread symbol/non-enumerable data into a plain object if needed."],"exampleFix":"// before\nconst config = loadConfig() ?? {};\nassert.nonEmptyObject(config); // throws on missing config file\n// after\nconst config = loadConfig();\nif (!is.nonEmptyObject(config)) {\n  throw new Error('config.json is missing or empty — create it with at least one setting');\n}","handlingStrategy":"validation","validationCode":"if (is.object(value) && Object.keys(value).length > 0) {\n  assert.nonEmptyObject(value);\n}","typeGuard":"function isNonEmptyObject(v: unknown): v is Record<string, unknown> {\n  return typeof v === 'object' && v !== null && !Array.isArray(v) && Object.keys(v).length > 0;\n}","tryCatchPattern":"try {\n  assert.nonEmptyObject(options);\n} catch (error) {\n  if (error instanceof TypeError) {\n    // options is {}, null, or not a plain object — apply required defaults or reject\n  }\n  throw error;\n}","preventionTips":["Check Object.keys(obj).length > 0 before asserting objects built from optional inputs","Note that objects with only symbol keys or non-enumerable keys count as empty here","Don't pass {} as a default when the API requires at least one property — make the property required"],"tags":["assertion","type-check","object","typescript"],"analyzedSha":"7821031c66cdeb7256a0feb2d506535f9e84fcaf","analyzedAt":"2026-07-31T18:34:06.268Z","schemaVersion":2}