{"id":"1427fb29aa4cfb53","repo":"sindresorhus/is","slug":"expected-value-which-is-non-empty-array-receive","errorCode":null,"errorMessage":"Expected value which is `non-empty array`, received value of type `${is(value)}`.","messagePattern":"Expected value which is `non-empty array`, received value of type `(.+?)`\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"source/index.ts","lineNumber":1743,"sourceCode":"\t\tthrow new TypeError(message ?? typeErrorMessage('negative integer', value));\n\t}\n}\n\nexport function assertNegativeNumber(value: unknown, message?: string): asserts value is number {\n\tif (!isNegativeNumber(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('negative number', value));\n\t}\n}\n\nexport function assertNodeStream(value: unknown, message?: string): asserts value is NodeStream {\n\tif (!isNodeStream(value)) {\n\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));","sourceCodeStart":1725,"sourceCodeEnd":1761,"githubUrl":"https://github.com/sindresorhus/is/blob/7821031c66cdeb7256a0feb2d506535f9e84fcaf/source/index.ts#L1725-L1761","documentation":"Thrown by `assertNonEmptyArray()` (source/index.ts:1741) in the @sindresorhus/is library when the checked value fails `isNonEmptyArray()`. The assertion requires the value to be an actual Array with `length > 0`; on failure it throws a TypeError whose message interpolates the detected type of the received value. The assert form narrows the value to the tuple type `[Item, ...Item[]]` for TypeScript, so it must throw instead of returning.","triggerScenarios":"Calling `assert.nonEmptyArray(value)` (or `assertNonEmptyArray`) with `[]`, with a non-array such as a string, Set, arguments object, typed array, or array-like `{length: 1}`, or with `undefined`/`null` from a missing input.","commonSituations":"Validating function arguments or API payloads where an upstream query, `.filter()`, or JSON parse unexpectedly produced an empty array; passing an array-like (NodeList, arguments) instead of a real array; config fields that default to empty lists.","solutions":["Ensure the array is populated before asserting — guard with `if (is.nonEmptyArray(value))` if empty is a legitimate state instead of asserting.","Convert array-likes with `Array.from(value)` or `[...value]` before the assertion.","Trace why the producer returned an empty array (over-strict filter, empty query result, wrong config key) and fix the source.","Pass a custom `message` argument to make the failure context clearer at the call site."],"exampleFix":"// before\nconst items = data.results.filter(r => r.active);\nassert.nonEmptyArray(items); // throws when all filtered out\n// after\nconst items = data.results.filter(r => r.active);\nif (!is.nonEmptyArray(items)) {\n  return []; // empty is a valid state here\n}\nprocess(items);","handlingStrategy":"validation","validationCode":"if (Array.isArray(value) && value.length > 0) {\n  assert.nonEmptyArray(value);\n}","typeGuard":"function isNonEmptyArray<T>(v: unknown): v is [T, ...T[]] {\n  return Array.isArray(v) && v.length > 0;\n}","tryCatchPattern":"try {\n  assert.nonEmptyArray(items);\n} catch (error) {\n  if (error instanceof TypeError) {\n    // items missing or empty — supply required data or reject the request\n  }\n  throw error;\n}","preventionTips":["Use is.nonEmptyArray(value) as a pre-check instead of relying on the assert to throw","Check .length > 0 before passing arrays sourced from filters, queries, or API responses","Treat an empty result set as a distinct, expected case in your control flow, not an exception","Model required-non-empty lists in your types (e.g. [T, ...T[]]) so emptiness is caught at compile time"],"tags":["assertion","type-check","array","typescript"],"analyzedSha":"7821031c66cdeb7256a0feb2d506535f9e84fcaf","analyzedAt":"2026-07-31T18:34:06.268Z","schemaVersion":2}