Closed nandi95 closed 1 year ago
useTrackEvent doesn't have the same typing as the useGtag()('event', ....nicely typed args)
useGtag()('event', ....nicely typed args)
I tried to implement this but didn't get far with it. Not easy when I only have the GTag type to work with.
import type { Gtag } from '../types' import { useGtag } from './useGtag' type Event = Gtag | ((command: 'event') => never) type OmitCommandParameter<T> = T extends (command: 'event', ...rest: infer R) => void ? (...args: R) => void : never export function useTrackEvent( eventName: Parameters<OmitCommandParameter<Event>>[0], eventParams?: Parameters<OmitCommandParameter<Event>>[1], ) { const { gtag } = useGtag() gtag('event', eventName, eventParams) }
Perhaps other types can be exported too? It would make sense in case someone constructs the arguments outside of a function call.
Valid point! Thanks for the hint and verbose issue description. 🙂
Describe the feature
useTrackEvent doesn't have the same typing as the
useGtag()('event', ....nicely typed args)
I tried to implement this but didn't get far with it. Not easy when I only have the GTag type to work with.
Perhaps other types can be exported too? It would make sense in case someone constructs the arguments outside of a function call.
Additional information
Final checks