Skip to content

types aren't compatible between createWrapper returned function and AnalyticsBrowser #1305

@YoFirmy

Description

@YoFirmy

We're trying to set up our analytics with the withOneTrust wrapper in packages/consent/consent-wrapper-onetrust. We've followed the documentation for npm library users, which is essentially just this snippet:

import { withOneTrust } from '@segment/analytics-consent-wrapper-onetrust'
import { AnalyticsBrowser } from '@segment/analytics-next'

export const analytics = new AnalyticsBrowser()

withOneTrust(analytics).load({ writeKey: '<MY_WRITE_KEY'> })

Everything seems to work but we get a typescript error in our code. The issue seems to be the writeKeyOrSettings argument on the load method of the analyticsInstance that is supposed to be passed to the withOneTrust wrapper. The withOneTrust wrapper has it typed as AnalyticsBrowserSettings | string, but the load method on the analyticsInstance does not have string as an option for it's first argument.

Here is the full type error:

Argument of type 'AnalyticsBrowser' is not assignable to parameter of type 'AnyAnalytics'.
  Types of property 'load' are incompatible.
    Type '(settings: AnalyticsBrowserSettings, options?: InitOptions | undefined) => AnalyticsBrowser' is not assignable to type '(writeKeyOrSettings: string | AnalyticsBrowserSettings, options?: InitOptions | undefined) => void'.
      Types of parameters 'settings' and 'writeKeyOrSettings' are incompatible.
        Type 'string | AnalyticsBrowserSettings' is not assignable to type 'AnalyticsBrowserSettings'.
          Type 'string' is not assignable to type 'AnalyticsBrowserSettings'.

Version information in case it is relevant: we're importing withOneTrust from "@segment/analytics-consent-wrapper-onetrust": "1.1.2", and AnalyticsBrowser from "@segment/analytics-next": "1.75.0".

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions