usablica/intro.js · error

Provided callback for onhintclose was not a function.

Error message

Provided callback for onhintclose was not a function.

What it means

Hint class onHintClose registers a callback fired when a hint is closed. Its if/else structure throws this exact error in the else branch when isFunction(providedCallback) is false. Same defensive contract as the other hint setters: callbacks must be functions.

Source

Thrown at src/packages/hint/hint.ts:439

  }

  /**
   * @deprecated onhintclick is deprecated, please use onHintClick instead
   * @param providedCallback
   */
  onhintclick(providedCallback: hintClickCallback) {
    this.onHintClick(providedCallback);
  }

  /**
   * Callback for when hint items are closed
   * @param providedCallback callback function
   */
  onHintClose(providedCallback: hintCloseCallback) {
    if (isFunction(providedCallback)) {
      this.callbacks.hintClose = providedCallback;
    } else {
      throw new Error("Provided callback for onhintclose was not a function.");
    }
    return this;
  }

  /**
   * @deprecated onhintclose is deprecated, please use onHintClose instead
   * @param providedCallback
   */
  onhintclose(providedCallback: hintCloseCallback) {
    this.onHintClose(providedCallback);
  }
}

View on GitHub (pinned to e5517e6a24)

Solutions

  1. Call onHintClose with a concrete function: introJs().onHintClose(function(hintObject){ ... }).
  2. Inspect the argument: ensure the callback variable is defined at call time and typeof === 'function'.
  3. Replace deprecated onhintclose usage with onHintClose and pass the function directly.
  4. Fix async assignment order — register the callback only after the handler is loaded.
  5. Add a caller-side guard to skip or default the registration.

Example fix

// before
introJs().onHintClose(opts.onClose); // opts.onClose is undefined
// after
if (typeof opts.onClose === 'function') {
  introJs().onHintClose(opts.onClose);
}
Defensive patterns

Strategy: validation

Validate before calling

if (typeof closeCb === 'function') { introJs().onHintClose(closeCb); }

Type guard

function isCallback(v: unknown): v is () => void { return typeof v === 'function'; }

Try / catch

try {
  intro().onHintClose(cb);
} catch (e) {
  if (String(e.message).includes('onhintclose was not a function')) {
    console.warn('Skipping onHintClose registration: bad callback');
  } else { throw e; }
}

Prevention

When it happens

Trigger: introJs().onHintClose() with no argument, or with a non-function such as null, an async wrapper object, or a Promise, typically from an undefined variable or wrong config key.

Common situations: Using the deprecated lowercase alias onhintclose with code written for a different callback signature; TypeScript users passing possibly-undefined values from optional config; assigning callbacks inside conditions that don't run.

Related errors


AI-assisted analysis of usablica/intro.js@e5517e6a24 (2026-08-31). Data as JSON: /api/errors/3c2eaf649aa6d8bc. Report an issue: GitHub.