sindresorhus/is · error · TypeError
Expected value which is `empty object`, received value of ty
Error message
Expected value which is `empty object`, received value of type `${is(value)}`. What it means
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)`.
Source
Thrown at source/index.ts:1568
throw new TypeError(message ?? typeErrorMessage('T', instance));
}
}
export function assertEmptyArray(value: unknown, message?: string): asserts value is never[] {
if (!isEmptyArray(value)) {
throw new TypeError(message ?? typeErrorMessage('empty array', value));
}
}
export function assertEmptyMap(value: unknown, message?: string): asserts value is Map<never, never> {
if (!isEmptyMap(value)) {
throw new TypeError(message ?? typeErrorMessage('empty map', value));
}
}
export function assertEmptyObject<Key extends keyof any = string>(value: unknown, message?: string): asserts value is Record<Key, never> {
if (!isEmptyObject(value)) {
throw new TypeError(message ?? typeErrorMessage('empty object', value));
}
}
export function assertEmptySet(value: unknown, message?: string): asserts value is Set<never> {
if (!isEmptySet(value)) {
throw new TypeError(message ?? typeErrorMessage('empty set', value));
}
}
export function assertEmptyString(value: unknown, message?: string): asserts value is '' {
if (!isEmptyString(value)) {
throw new TypeError(message ?? typeErrorMessage('empty string', value));
}
}
export function assertEmptyStringOrWhitespace(value: unknown, message?: string): asserts value is '' | Whitespace {
if (!isEmptyStringOrWhitespace(value)) {
throw new TypeError(message ?? typeErrorMessage('empty string or whitespace', value));View on GitHub ↗ (pinned to 7821031c66)
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
Example fix
// before
assert.emptyObject({debug: false}); // has a key, throws
// after
assert.emptyObject({}); Defensive patterns
Strategy: type-guard
Validate before calling
if (is.plainObject(value) && Object.keys(value).length === 0) {
assert.emptyObject(value);
} Type guard
function isEmptyObject(value: unknown): value is Record<string, never> {
return is.plainObject(value) && Object.keys(value).length === 0;
} Try / catch
try {
assert.emptyObject(value);
} catch (error) {
if (error instanceof TypeError) {
// not an empty plain object — arrays, Maps, class instances all fail here
} else throw error;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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 `{}`.
Related errors
- Expected value which is `empty map`, received value of type
- Expected value which is `empty set`, received value of type
- Expected value which is `empty string`, received value of ty
- Expected value which is `empty string or whitespace`, receiv
- Expected value which is `EnumCase`, received value of type `
AI-assisted analysis of sindresorhus/is@7821031c66 (2026-07-31).
Data as JSON: /data/errors/7699f12c6c6e6a9d.json.
Report an issue: GitHub ↗.