{"record":{"id":"5ecadeaf7c570681","repo":"alvarotrigo/fullPage.js","slug":"array-from-when-provided-the-second-argument-mus","errorCode":null,"errorMessage":"Array.from: when provided, the second argument must be a function","messagePattern":"Array\\.from: when provided, the second argument must be a function","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/js/polyfills/array.from.js","lineNumber":49,"sourceCode":"\n            // 2. Let items be ToObject(arrayLike).\n            var items = Object(arrayLike);\n\n            // 3. ReturnIfAbrupt(items).\n            if (arrayLike == null) {\n                throw new TypeError(\n                    'Array.from requires an array-like object - not null or undefined'\n                );\n            }\n\n            // 4. If mapfn is undefined, then let mapping be false.\n            var mapFn = arguments.length > 1 ? arguments[1] : void undefined;\n            var T;\n            if (typeof mapFn !== 'undefined') {\n                // 5. else\n                // 5. a If IsCallable(mapfn) is false, throw a TypeError exception.\n                if (!isCallable(mapFn)) {\n                    throw new TypeError(\n                        'Array.from: when provided, the second argument must be a function'\n                    );\n                }\n\n                // 5. b. If thisArg was supplied, let T be thisArg; else let T be undefined.\n                if (arguments.length > 2) {\n                    T = arguments[2];\n                }\n            }\n\n            // 10. Let lenValue be Get(items, \"length\").\n            // 11. Let len be ToLength(lenValue).\n            var len = toLength(items.length);\n\n            // 13. If IsConstructor(C) is true, then\n            // 13. a. Let A be the result of calling the [[Construct]] internal method\n            // of C with an argument list containing the single item len.\n            // 14. a. Else, Let A be ArrayCreate(len).","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/alvarotrigo/fullPage.js/blob/49f15effa7b195def295a36f872c28153cf9fb00/src/js/polyfills/array.from.js#L31-L67","documentation":"Thrown by the Array.from polyfill (src/js/polyfills/array.from.js:49) at spec step 5a. When the second argument (mapFn) is provided (i.e. arguments.length > 1 and the value is not undefined), the polyfill runs isCallable(mapFn); if it is not a function, this TypeError is thrown. The native Array.from produces the same error.","triggerScenarios":"Calling Array.from(items, 5), Array.from(items, 'toString'), Array.from(items, null), or Array.from(items, mapper) where mapper is not a function; passing an optional third positional by mistake into the second slot.","commonSituations":"Reading a mapper from config that is undefined when disabled but still passed positionally; passing a string method name instead of a bound function; a refactor that changed a function value into something else without updating the call site.","solutions":["Pass a real function as the second argument: Array.from(items, x => x.id).","If you only need conversion with no mapping, omit the second argument entirely.","Conditionally pass the mapper only when it is a function: Array.from(items, typeof mapper === 'function' ? mapper : undefined).","Validate the value at its source and fix the assignment that produced a non-function."],"exampleFix":"// before\nconst ids = Array.from(rows, 'id');\n// Array.from: when provided, the second argument must be a function\n\n// after\nconst ids = Array.from(rows, row => row.id);","handlingStrategy":"type-guard","validationCode":"function fromWith(items, mapFn) {\n  return Array.isArray(items) ? items.slice() : Array.from(items, typeof mapFn === 'function' ? mapFn : undefined);\n}","typeGuard":"const isCallable = (v) => typeof v === 'function';\n// usage: Array.from(items, isCallable(mapFn) ? mapFn : undefined);","tryCatchPattern":null,"preventionTips":["Only pass mapFn when it is genuinely a function; otherwise omit the argument.","Coerce optional mappers: typeof mapper === 'function' ? mapper : undefined before the call.","Avoid passing positional placeholders (null/0/strings) where a mapper is expected."],"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"}