TypeScript Support


Overview

As of the latest release, @understand/understand-js ships with TypeScript type definitions. No additional @types package is needed.

Available Types

The package exports the following interfaces:

  • UnderstandOptions — options passed to Understand.init()
  • CatchErrorOptions — options passed to Understand.catchErrors()
  • PatchConsoleOptions — options passed to Understand.patchConsoleLogs()

Usage Example

import Understand, {
  UnderstandOptions,
  CatchErrorOptions,
  PatchConsoleOptions
} from '@understand/understand-js';

const options: UnderstandOptions = {
  env: 'production',
  token: '<your-input-token>',
  context: {
    user_id: 42,
    client_ip: '141.93.46.10'
  }
};

const catchOptions: CatchErrorOptions = {
  enableWindowError: true,
  enableUnhandledRejection: true,
  enableConsoleError: true
};

const consoleOptions: PatchConsoleOptions = {
  enableConsoleLog: true,
  enableConsoleInfo: true,
  enableConsoleWarn: true,
  enableConsoleDebug: true
};

Understand.init(options).catchErrors(catchOptions);
Understand.patchConsoleLogs(consoleOptions);

You can also use the global Understand instance directly if you prefer not to import types explicitly:

Understand.init({
  env: 'production',
  token: '<your-input-token>'
}).catchErrors();