pushInstriction type mismatch. Could reuse MatomoInstance interface
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.