{"id":"81d035f23b179adc","repo":"sindresorhus/is","slug":"invalid-predicate-array","errorCode":null,"errorMessage":"Invalid predicate array","messagePattern":"Invalid predicate array","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"source/index.ts","lineNumber":399,"sourceCode":"\t\tweakRef: isWeakRef,\n\t\tweakSet: isWeakSet,\n\t\twhitespaceString: isWhitespaceString,\n\t},\n);\n\nfunction isAbsoluteModule2(remainder: 0 | 1) {\n\treturn (value: unknown): value is number => isInteger(value) && Math.abs(value % 2) === remainder;\n}\n\ntype TypeGuard<T> = (value: unknown) => value is T;\n\nfunction validatePredicateArray(predicateArray: readonly Predicate[], allowEmpty: boolean) {\n\tif (predicateArray.length === 0) {\n\t\tif (allowEmpty) {\n\t\t\t// Next major release: throw for empty predicate arrays to avoid vacuous results.\n\t\t\t// throw new TypeError('Invalid predicate array');\n\t\t} else {\n\t\t\tthrow new TypeError('Invalid predicate array');\n\t\t}\n\n\t\treturn;\n\t}\n\n\tfor (const predicate of predicateArray) {\n\t\tvalidatePredicate(predicate);\n\t}\n}\n\nfunction validatePredicate(predicate: Predicate) {\n\tif (!isFunction(predicate)) {\n\t\tthrow new TypeError(`Invalid predicate: ${JSON.stringify(predicate)}`);\n\t}\n}\n\n// Predicate factory overloads - return a type guard when called with only predicates\nexport function isAll<T1>(predicates: [TypeGuard<T1>]): TypeGuard<T1>;","sourceCodeStart":381,"sourceCodeEnd":417,"githubUrl":"https://github.com/sindresorhus/is/blob/7821031c66cdeb7256a0feb2d506535f9e84fcaf/source/index.ts#L381-L417","documentation":"Thrown by `validatePredicateArray` (source/index.ts:393) when a predicate array passed to a combinator like `isAll`/`isAny` (or their assert counterparts) is empty and empty arrays are not allowed in that call path. An empty predicate array would produce vacuous results (everything or nothing matches), so the library rejects it; a comment notes the next major release will throw for the currently-allowed empty cases too.","triggerScenarios":"Calling `isAny([])`, `assertAny([], ...)`, or another predicate-array API with a zero-length array in a code path where `allowEmpty` is false. Typically the array is built dynamically (filter/map) and ends up empty.","commonSituations":"Dynamically building a predicate list from configuration or feature flags and all entries get filtered out; refactoring that removes the last predicate from a shared list; passing the wrong variable (an empty array) by mistake.","solutions":["Ensure the predicate array contains at least one type-guard function before calling the combinator.","If the list is built dynamically, guard the call: skip validation or treat it as pass/fail explicitly when the list is empty.","Check for variable mix-ups — confirm you're passing the intended, populated array."],"exampleFix":"// before\nconst predicates = [];\nisAny(predicates, value); // throws TypeError\n\n// after\nconst predicates = [is.string, is.number];\nisAny(predicates, value);","handlingStrategy":"validation","validationCode":"if (!Array.isArray(predicates) || predicates.length === 0) {\n  throw new TypeError('Expected a non-empty array of predicates');\n}","typeGuard":"function isPredicateArray(v: unknown): v is Function[] {\n  return Array.isArray(v) && v.length > 0 && v.every(p => typeof p === 'function' || typeof p === 'object');\n}","tryCatchPattern":null,"preventionTips":["Pass predicates as a literal array (e.g. `is.any([is.string, is.number], value)`) rather than a dynamically built one","If building the predicate list dynamically, assert it is non-empty before calling","Type the predicate list as a non-empty tuple in TypeScript (`[Predicate, ...Predicate[]]`)"],"tags":["validation","predicate","empty-array"],"analyzedSha":"7821031c66cdeb7256a0feb2d506535f9e84fcaf","analyzedAt":"2026-07-31T18:34:06.268Z","schemaVersion":2}