Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useTrackEvent typing improvement #28

Closed
2 of 3 tasks
nandi95 opened this issue Sep 14, 2023 · 1 comment
Closed
2 of 3 tasks

useTrackEvent typing improvement #28

nandi95 opened this issue Sep 14, 2023 · 1 comment

Comments

@nandi95
Copy link

nandi95 commented Sep 14, 2023

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.

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.

Additional information

  • Would you be willing to help implement this feature?
  • Can you think of other implementations of this feature?

Final checks

@johannschopplich
Copy link
Owner

Valid point! Thanks for the hint and verbose issue description. 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants