Refine JSDoc / TypeScript types for plugins#324
Refine JSDoc / TypeScript types for plugins#324dobesv wants to merge 2 commits intoDavidWells:masterfrom
Conversation
| * @property {Once} once - Fire callback on analytics lifecycle events once. | ||
| * @property {GetState} getState - Get data about user, activity, or context. | ||
| * @property {Storage} storage - storage methods | ||
| * @property {AnalyticsStorage} storage - storage methods |
There was a problem hiding this comment.
This conflicted with the built-in type Storage used for localStorage & sessionStorage so I took the liberty of renaming it while I was in here to fix the TypeScript error I got. Hopefully that's OK.
eea7d2f to
6b023a9
Compare
| * @param {AnalyticsInstance} arg.instance analytics instance | ||
| * @param {Object} arg.payload event data | ||
| * @param {string} arg.payload.event event name passed to track | ||
| * @param {TrackEventProperties} [arg.payload.properties] event properties passed to track |
There was a problem hiding this comment.
Not sure if this is actually optional. Will the library always supply an object here?
|
|
||
| /** | ||
| * Track data for overrides | ||
| * @typedef {Object.<string>} TrackEventProperties |
There was a problem hiding this comment.
Just a generic map here since there's no predefined fields for this
6b023a9 to
95a7fa5
Compare
95a7fa5 to
1c26a40
Compare
| * @property {PluginPageFunction} [page] - Page visit tracking method | ||
| * @property {PluginTrackFunction} [track] - Custom event tracking method | ||
| * @property {PluginIdentifyFunction} [identify] - User identify method | ||
| * @property {PluginLoadedFunction} [loaded] - Function to determine if analytics script loaded | ||
| * @property {PluginReadyFunction} [ready] - Fire function when plugin ready |
There was a problem hiding this comment.
Should there be one of these for every event named in events.js ?
|
Working on this it does feel like maintaining separate |
|
This would be a very welcome addition as all the plugin methods are typed simply |
There was a problem hiding this comment.
Would it make sense to add meta, anonymousId and userId as well? I haven't entirely figured which are present in what methods always.
https://getanalytics.io/resources/faq/#do-i-need-to-use-a-plugin
There was a problem hiding this comment.
Well, maybe? Doesn't seem like this PR is getting any attention from the library maintainer so I'm not sure making any changes to it makes practical sense.
There was a problem hiding this comment.
Yeah, it seems like issues and PRs are increasing. I'm sure @DavidWells is just busy at the moment. Maybe it's time for a call for maintainers? 🤔
|
@DavidWells do you have any feedback on this one? Should I revise it, close it, anything? |
Starting working on improving the JSDoc / TypeScript a bit so that I could better understand the types here.
I'm not totally sure these are quite correct.
Also - can plugins define all the events defined in
events.js? It seems like the JSDoc currently only lists a few events.