{"record":{"id":"671bc26863d7e3d6","repo":"usablica/intro.js","slug":"provided-callback-for-onhintsadded-was-not-a-funct","errorCode":null,"errorMessage":"Provided callback for onhintsadded was not a function.","messagePattern":"Provided callback for onhintsadded was not a function\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/packages/hint/hint.ts","lineNumber":395,"sourceCode":"  }\n\n  /**\n   * Clone the Hint instance\n   */\n  clone(): ThisType<this> {\n    return new Hint(this._targetElement, this._options);\n  }\n\n  /**\n   * Returns true if the Hint is active\n   */\n  isActive(): boolean {\n    return this.getOption(\"isActive\");\n  }\n\n  onHintsAdded(providedCallback: hintsAddedCallback) {\n    if (!isFunction(providedCallback)) {\n      throw new Error(\"Provided callback for onhintsadded was not a function.\");\n    }\n\n    this.callbacks.hintsAdded = providedCallback;\n    return this;\n  }\n\n  /**\n   * @deprecated onhintsadded is deprecated, please use onHintsAdded instead\n   * @param providedCallback callback function\n   */\n  onhintsadded(providedCallback: hintsAddedCallback) {\n    this.onHintsAdded(providedCallback);\n  }\n\n  /**\n   * Callback for when hint items are clicked\n   * @param providedCallback callback function\n   */","sourceCodeStart":377,"sourceCodeEnd":413,"githubUrl":"https://github.com/usablica/intro.js/blob/e5517e6a24e0530f87885af9fb2a69bafd1d4a6b/src/packages/hint/hint.ts#L377-L413","documentation":"intro.js's Hint class method onHintsAdded registers a callback invoked after hints are added. Before storing it in this.callbacks.hintsAdded, it validates the argument with isFunction and throws this error when the argument is not a function. This is a defensive guard so later invocation sites never crash calling a non-function.","triggerScenarios":"Calling introJs().addHints() config path or hintObject registration where onHintsAdded(...) is passed undefined, null, a string, or a wrongly-named variable instead of a function, e.g. introJs().onHintsAdded().","commonSituations":"Typo'd callback names loaded as undefined; passing an object like {cb: fn} instead of the function itself; migrating from older intro.js versions where the setter silently accepted anything; calling before the callback variable is assigned (async load order).","solutions":["Pass an actual function: introJs().onHintsAdded(function(hints, hintObjects){ ... }).","Log the value with console.log(typeof myCb) and fix the variable that is undefined or not a function.","Check option-object style config (hints-added / onHintsAdded key) and ensure the value is a function, not its name or result of calling the function.","Update code that used the deprecated lowercase alias onhintsadded if it passes a non-function.","Wrap the call in a try/catch to surface the misconfiguration early."],"exampleFix":"// before\nconst myCb = config.hintsCb; // undefined (typo: config.hintsCallback)\nintroJs().onHintsAdded(myCb);\n// after\nintroJs().onHintsAdded(function(hints) {\n  console.log('hints added', hints);\n});","handlingStrategy":"validation","validationCode":"if (typeof cb !== 'function') { throw new TypeError('onHintsAdded expects a function, got ' + typeof cb); }\nintroJs().onHintsAdded(cb);","typeGuard":"function isCallable(v) { return typeof v === 'function'; }","tryCatchPattern":"try {\n  introJs().onHintsAdded(cb);\n} catch (e) {\n  if (e.message.includes('onhintsadded was not a function')) {\n    console.error('Bad hints-added callback:', cb);\n  } else { throw e; }\n}","preventionTips":["Always pass function references, not names or results of calls","TypeScript: type callbacks as ((hints: HTMLElement[]) => void) | undefined and check before use","Default optional callbacks to a no-op function at config load time","Register callbacks in initialization code after all handlers are defined","Avoid the deprecated lowercase aliases; use camelCase setters"],"tags":["callbacks","type-validation","api-misuse"],"backgroundTag":"callback-not-a-function","analyzedSha":"e5517e6a24e0530f87885af9fb2a69bafd1d4a6b","analyzedAt":"2026-08-31T22:12:26.007Z","schemaVersion":2},"datasetVersion":"2026-08-31T22:30:34.772Z"}