{"record":{"id":"06b9cb85c248f0d8","repo":"alvarotrigo/fullPage.js","slug":"predicate-must-be-a-function","errorCode":null,"errorMessage":"predicate must be a function","messagePattern":"predicate must be a function","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/js/polyfills/array.find.js","lineNumber":17,"sourceCode":"// https://tc39.github.io/ecma262/#sec-array.prototype.find\nif (!Array.prototype.find) {\n    Object.defineProperty(Array.prototype, 'find', {\n        value: function(predicate) {\n            // 1. Let O be ? ToObject(this value).\n            if (this == null) {\n                throw new TypeError('\"this\" is null or not defined');\n            }\n\n            var o = Object(this);\n\n            // 2. Let len be ? ToLength(? Get(O, \"length\")).\n            var len = o.length >>> 0;\n\n            // 3. If IsCallable(predicate) is false, throw a TypeError exception.\n            if (typeof predicate !== 'function') {\n                throw new TypeError('predicate must be a function');\n            }\n\n            // 4. If thisArg was supplied, let T be thisArg; else let T be undefined.\n            var thisArg = arguments[1];\n\n            // 5. Let k be 0.\n            var k = 0;\n\n            // 6. Repeat, while k < len\n            while (k < len) {\n                // a. Let Pk be ! ToString(k).\n                // b. Let kValue be ? Get(O, Pk).\n                // c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)).\n                // d. If testResult is true, return kValue.\n                var kValue = o[k];\n                if (predicate.call(thisArg, kValue, k, o)) {\n                    return kValue;\n                }","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/alvarotrigo/fullPage.js/blob/49f15effa7b195def295a36f872c28153cf9fb00/src/js/polyfills/array.find.js#L1-L35","documentation":"Thrown by the Array.prototype.find polyfill (src/js/polyfills/array.find.js:17) at spec step 3, IsCallable(predicate). After the receiver is validated and length coerced, the polyfill checks typeof predicate !== 'function' and throws this message if the callback is not callable. The native method throws the same TypeError, so this polyfill path is only reached when Array.prototype.find is absent.","triggerScenarios":"Calling arr.find() with no arguments; passing a non-function such as arr.find(null), arr.find(undefined), arr.find('name'), arr.find({}), or arr.find(someVar) where someVar resolved to a non-function value.","commonSituations":"Typo in a method name passed as the predicate; conditional code that omits the callback; reading a callback from config that is undefined when a feature flag is off; passing a property name string instead of a comparison function.","solutions":["Pass a real function predicate: arr.find(item => item.active).","If the predicate comes from config or an optional argument, default it or guard before calling: arr.find(predicate || (() => false)).","Trace predicate back to its source and fix the assignment/import that produced a non-function.","Verify the polyfill is active only on target browsers; on modern browsers the native find throws the equivalent error, so the fix is the same."],"exampleFix":"// before\nconst match = items.find('id');\n// predicate must be a function\n\n// after\nconst match = items.find(item => item.id === 'id');","handlingStrategy":"validation","validationCode":"function findWith(items, predicate) {\n  if (!Array.isArray(items)) {\n    throw new TypeError('expected an array');\n  }\n  if (typeof predicate !== 'function') {\n    throw new TypeError('predicate must be a function, got ' + typeof predicate);\n  }\n  return items.find(predicate);\n}","typeGuard":"const isFunction = (v) => typeof v === 'function';\n// usage: if (isFunction(predicate)) items.find(predicate);","tryCatchPattern":null,"preventionTips":["Treat the predicate as required input: assert typeof predicate === 'function' before the call.","When the callback is optional from config, default it to a stable no-match function.","Enable a linter rule (e.g., @typescript-eslint/no-unbound-method) to catch detached/invalid method references."],"tags":["polyfill","array","callback","type-validation","es2015"],"backgroundTag":null,"analyzedSha":"49f15effa7b195def295a36f872c28153cf9fb00","analyzedAt":"2026-08-13T04:33:34.972Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}