analytics icon indicating copy to clipboard operation
analytics copied to clipboard

Mixpanel types

Open JuroOravec opened this issue 5 years ago • 2 comments
trafficstars

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/types script similar to one in @analytics/core.
    • The script post-processes the generated types.d.ts to export plugin config and plugin interfaces.
  • Add analytics as a dependency so types in types.d.ts can 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

JuroOravec avatar Nov 15 '20 19:11 JuroOravec

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

DavidWells avatar Jan 14 '21 05:01 DavidWells

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.

mattcasey avatar Jan 12 '23 20:01 mattcasey