{"id":"bb728ba4a5567f71","repo":"sindresorhus/is","slug":"expected-value-which-is-empty-array-received-va","errorCode":null,"errorMessage":"Expected value which is `empty array`, received value of type `${is(value)}`.","messagePattern":"Expected value which is `empty array`, received value of type `(.+?)`\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"source/index.ts","lineNumber":1556,"sourceCode":"\t\tthrow new TypeError(message ?? typeErrorMessage('DataView', value));\n\t}\n}\n\nexport function assertDate(value: unknown, message?: string): asserts value is Date {\n\tif (!isDate(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('Date', value));\n\t}\n}\n\nexport function assertDirectInstanceOf<T>(instance: unknown, class_: Class<T>, message?: string): asserts instance is T {\n\tif (!isDirectInstanceOf(instance, class_)) {\n\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));","sourceCodeStart":1538,"sourceCodeEnd":1574,"githubUrl":"https://github.com/sindresorhus/is/blob/7821031c66cdeb7256a0feb2d506535f9e84fcaf/source/index.ts#L1538-L1574","documentation":"Thrown by `assertEmptyArray()` when the value fails `isEmptyArray` — it must be a real Array AND have length 0. Both a non-array (even an empty one, like `{}` or an empty Set) and a non-empty array trigger it. Used to enforce an expected empty-state invariant (e.g., no leftover errors, drained queue).","triggerScenarios":"Calling `assert.emptyArray(value)` with an array that still has elements (invariant violation), or with array-likes: an empty Set/Map, arguments object, NodeList, typed array, or a JSON-parsed object `{}`.","commonSituations":"Validation error collectors asserted empty at the end of a run while errors accumulated; queues expected drained but a race left items; using Set/NodeList where Array was assumed; test assertions expecting a cleanup step to have cleared state.","solutions":["If the value is a non-empty array, the assertion is doing its job — inspect the contents to fix the underlying invariant violation (e.g., handle the accumulated errors).","If the container type is wrong, convert first: `[...set]`, `Array.from(nodeList)` before asserting.","If a non-empty array is legitimately possible, replace the assertion with a branch: `if (errors.length > 0) { ... }`."],"exampleFix":"// before\nassert.emptyArray(validationErrors); // throws when errors exist\n// after — handle rather than assert when non-empty is expected\nif (validationErrors.length > 0) {\n\tthrow new AggregateError(validationErrors, 'Validation failed');\n}","handlingStrategy":"validation","validationCode":"if (!Array.isArray(value) || value.length !== 0) {\n  // expected an empty array — clear it or fix the producer that populated it\n}","typeGuard":"function isEmptyArray(value: unknown): value is [] {\n  return Array.isArray(value) && value.length === 0;\n}","tryCatchPattern":"try {\n  assert.emptyArray(value);\n} catch (error) {\n  if (error instanceof TypeError) {\n    // either not an array at all, or an array with elements — the message's type name tells you which\n  } else throw error;\n}","preventionTips":["This assertion checks both array-ness and length 0 — a non-empty array fails just like a non-array","If emptiness is the invariant (e.g. no leftover errors), log the actual contents on failure to see what leaked in","Array-likes (arguments, NodeList) are not arrays — spread or Array.from() them first"],"tags":["type-assertion","array","empty-check","invariant"],"analyzedSha":"7821031c66cdeb7256a0feb2d506535f9e84fcaf","analyzedAt":"2026-07-31T18:34:06.268Z","schemaVersion":2}