Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

pushInstriction type mismatch. Could reuse MatomoInstance interface #717

Open
KrzysztofMadejski opened this issue Dec 21, 2021 · 0 comments

Comments

@KrzysztofMadejski
Copy link

KrzysztofMadejski commented Dec 21, 2021

Is your feature request related to a problem? Please describe.
I'd like to use MatomoInstance consistently. useMatomo hook returns type not matching with the return type of createInstance.

I'd like to pass matomo client returned by useMatomo as typed by MatomoInstance.

Describe the solution you'd like

MatomoProvider takes MatomoInstance as a value which is defined as:

export interface MatomoInstance {
    trackEvent: MatomoTracker['trackEvent'];
    trackEvents: MatomoTracker['trackEvents'];
    trackPageView: MatomoTracker['trackPageView'];
    trackSiteSearch: MatomoTracker['trackSiteSearch'];
    trackLink: MatomoTracker['trackLink'];
    pushInstruction: MatomoTracker['pushInstruction']; // which resolves to pushInstruction(name: string, ...args: any[]): MatomoTracker;
}

, but useMatomo returns very close type, but different:

declare function useMatomo(): {
    trackEvent: (params: TrackEventParams) => void | undefined;
    trackEvents: () => void | undefined;
    trackPageView: (params: TrackPageViewParams) => void | undefined;
    trackSiteSearch: (params: TrackSiteSearchParams) => void | undefined;
    trackLink: (params: TrackLinkParams) => void | undefined;
    enableLinkTracking: () => void;
    pushInstruction: (name: string, ...args: any[]) => void;
};

The difference:

Argument of type '{ trackEvent: (params: TrackEventParams) => void | undefined; trackEvents: () => void | undefined; trackPageView: (params: TrackPageViewParams) => void | undefined; trackSiteSearch: (params: TrackSiteSearchParams) => void | undefined; trackLink: (params: TrackLinkParams) => void | undefined; enableLinkTracking: () =...' is not assignable to parameter of type 'MatomoInstance'.
  The types returned by 'pushInstruction(...)' are incompatible between these types.
    Type 'void' is not assignable to type 'MatomoTracker'.

Why not have simply

declare function useMatomo(): MatomoInstance;

Describe alternatives you've considered

I defined my own interface with a subset of functions I'm using:

export interface MatomoTracker {
  trackEvent: (params: TrackEventParams) => void | undefined;
}

But it only works because I'm not using pushInstruction I believe.

Additional context
Using version "0.3.1", updated to 0.5.1 but the types are defined still in the same way.

@KrzysztofMadejski KrzysztofMadejski changed the title Reuse MatomoInstance interface pushInstriction type mismatch. Could reuse MatomoInstance interface Dec 21, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant