analytics icon indicating copy to clipboard operation
analytics copied to clipboard

Property <<plugin name>> does not exist on type 'Plugins'

Open wlecki opened this issue 2 years ago • 6 comments

Hey! I'm creating a new plugin for the analytics lib :) It's almost ready to be published, but I'm getting this Typescript error when calling custom methods in my plugin:

image

I'm uncertain if that's something I missed in my configuration, or if that's something we can improve in the main analytics lib. I can prepare a PR here too.

wlecki avatar Mar 29 '22 09:03 wlecki

Mmmm not sure how exactly you'd type this.

Suggestions welcome.

DavidWells avatar Apr 03 '22 19:04 DavidWells

Hey :)

So I've found this script to generate typing, but I have hard time understanding it (thus, creating a PR): https://github.com/DavidWells/analytics/blob/e324d0c97797c5d661bb11c8f2014e05cb639564/packages/analytics-core/scripts/types.js

But the simplest solution would be to allow Record for plugins property on AnalyticsInstance like this:

export interface AnalyticsInstance  {
  identify: Identify;
  track: Track;
  page: Page;
  user: User;
  reset: Reset;
  ready: Ready;
  on: On;
  once: Once;
  getState: GetState;
  storage: Storage;
  plugins: Plugins & Record<string, any>;
}

Now plugins property is typed like this: plugins: Plugins;

wlecki avatar Jun 14 '22 12:06 wlecki

Using namespace and interface merging via globals is how my team accomplished this. We did unfortunately have to coerce to get it working if did some wrapping you could be probably get it to override directly.

shafferchance-lulu avatar Aug 26 '22 12:08 shafferchance-lulu

It would be a combination of @wlecki and a global declaration file.

shafferchance-lulu avatar Aug 26 '22 12:08 shafferchance-lulu

@shafferchance-lulu could you please share a snippet of our namespace and interface merging via globals? Thanks!

wlecki avatar Jan 12 '23 12:01 wlecki

Vite does a similar thing: https://vitejs.dev/guide/env-and-mode

deevus avatar Jan 25 '24 05:01 deevus