analytics
analytics copied to clipboard
Mixpanel types
Background
As a TypeScript user working with the @analytics/mixpanel plugin, I want to have the plugin (and primarily the plugin config) covered by TypeScript
After https://github.com/DavidWells/analytics/pull/114, adding TypeScript support is trivial as the plugin definition can be reused.
Changes
- Add type annotations to types and functions in
@analytics/mixpanel - Add
./scripts/typesscript similar to one in@analytics/core.- The script post-processes the generated
types.d.tsto export plugin config and plugin interfaces.
- The script post-processes the generated
- Add
analyticsas a dependency so types intypes.d.tscan import the types exposed in https://github.com/DavidWells/analytics/pull/114 - Add
'types'npm command to@analytics/mixpanel - Add
'temp-types'to.gitignore
Blocked by https://github.com/DavidWells/analytics/pull/114 and https://github.com/DavidWells/analytics/pull/115
Thanks for the PR as always 😃
I'm currently stuck on the issue where types can be different between server and client implementations but this isn't supported in typescript (or I can't figure out how to achieve this)
More details in thread https://twitter.com/DavidWells/status/1340059740672442368
Hi, random stranger here looking for a solution.. for now I'm just going to add my own .d.ts file. Here's an idea: let me import based on the types I want:
import mixpanelBrowserPlugin from '@analytics/mixpanel/browser'; // browser client
import mixpanelServerPlugin from '@analytics/mixpanel/node'; // node client
For me, I don't need isomorphic code even though I'm using a Next.js app. Having to opt into one or the other is better than having to write my own types. I think the issue is that the library determines the implementation at runtime, but at compile time, I'm not sure Typescript even has a concept of "node", you would at best need to be able to check if a type from the Node lib exists or not, but using undefined types just results in a compile error.