{"id":"0bc19e02b51d8782","repo":"sindresorhus/is","slug":"invalid-predicate-json-stringify-predicate","errorCode":null,"errorMessage":"Invalid predicate: ${JSON.stringify(predicate)}","messagePattern":"Invalid predicate: (.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"source/index.ts","lineNumber":412,"sourceCode":"\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>;\nexport function isAll<T1, T2>(predicates: [TypeGuard<T1>, TypeGuard<T2>]): TypeGuard<T1 & T2>;\nexport function isAll<T1, T2, T3>(predicates: [TypeGuard<T1>, TypeGuard<T2>, TypeGuard<T3>]): TypeGuard<T1 & T2 & T3>;\nexport function isAll<T1, T2, T3, T4>(predicates: [TypeGuard<T1>, TypeGuard<T2>, TypeGuard<T3>, TypeGuard<T4>]): TypeGuard<T1 & T2 & T3 & T4>;\nexport function isAll<T1, T2, T3, T4, T5>(predicates: [TypeGuard<T1>, TypeGuard<T2>, TypeGuard<T3>, TypeGuard<T4>, TypeGuard<T5>]): TypeGuard<T1 & T2 & T3 & T4 & T5>;\nexport function isAll(predicates: ReadonlyArray<TypeGuard<unknown>>): TypeGuard<unknown>;\nexport function isAll(predicates: readonly Predicate[]): Predicate;\n// Evaluator overload - check if all values match the predicate\nexport function isAll(predicate: Predicate | readonly Predicate[], ...values: unknown[]): boolean;\nexport function isAll(predicate: Predicate | readonly Predicate[], ...values: unknown[]): boolean | Predicate {\n\tif (Array.isArray(predicate)) {\n\t\tconst predicateArray = predicate as readonly Predicate[];\n\t\tvalidatePredicateArray(predicateArray, values.length === 0);\n","sourceCodeStart":394,"sourceCodeEnd":430,"githubUrl":"https://github.com/sindresorhus/is/blob/7821031c66cdeb7256a0feb2d506535f9e84fcaf/source/index.ts#L394-L430","documentation":"Thrown by `validatePredicate` (source/index.ts:410) when an element passed as a predicate to `isAll`/`isAny`/`assertAll`/`assertAny` (or inside a predicate array) is not a function. Every predicate must be a type-guard function `(value: unknown) => boolean`; the error message JSON-stringifies the offending value to aid debugging.","triggerScenarios":"Passing a non-function — string, undefined, object, or the *result* of calling a predicate — where a predicate function is expected, e.g. `isAll(is.string(x), y)` instead of `isAll(is.string, x, y)`, or a predicate array containing `undefined` from a typo'd property access like `is.strin`.","commonSituations":"Accidentally invoking the predicate instead of passing the function reference; typos in `is.xxx` property names yielding `undefined`; passing a string type name ('string') expecting Jest/Joi-style APIs; version upgrades where a method was renamed or removed.","solutions":["Pass the function reference, not its result: `isAll(is.string, a, b)` rather than `isAll(is.string(a), b)`.","Check the stringified value in the message — `undefined` usually means a typo'd `is.` property name; verify the method exists in your installed version.","If using a custom predicate, ensure the variable actually holds a function at the call site."],"exampleFix":"// before\nassertAll(is.string(name), name, title); // passes boolean, throws\n\n// after\nassertAll(is.string, name, title);","handlingStrategy":"validation","validationCode":"const validPredicates = new Set(Object.values(is));\npredicates.forEach(p => {\n  if (typeof p !== 'function' && !validPredicates.has(p)) {\n    throw new TypeError(`Not a library predicate: ${String(p)}`);\n  }\n});","typeGuard":"function isKnownPredicate(p: unknown): p is (v: unknown) => boolean {\n  return typeof p === 'function';\n}","tryCatchPattern":null,"preventionTips":["Only pass predicates exported by the library itself (e.g. `is.string`), not strings like `'string'` or ad-hoc values","Don't call the predicate when passing it — pass `is.number`, not `is.number(x)` (the result is a boolean, an invalid predicate)","Rely on TypeScript's types for the predicate parameter instead of `any`-casting"],"tags":["validation","predicate","api-misuse"],"analyzedSha":"7821031c66cdeb7256a0feb2d506535f9e84fcaf","analyzedAt":"2026-07-31T18:34:06.268Z","schemaVersion":2}