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

Add generic type for SelfDescribing event data #156

Closed
henbrand opened this issue Mar 3, 2022 · 3 comments
Closed

Add generic type for SelfDescribing event data #156

henbrand opened this issue Mar 3, 2022 · 3 comments
Labels
type:enhancement New features or improvements to existing features.
Milestone

Comments

@henbrand
Copy link
Contributor

henbrand commented Mar 3, 2022

Hi! 👋

For additional type safety I wanted to be able to type the data object for trackSelfDescribingEvent, currently I have patched the library to allow me to do so. Let me know if you'd like me to open a pull request!

Here is the diff that solved my problem:

diff --git a/node_modules/@snowplow/react-native-tracker/dist/index.d.ts b/node_modules/@snowplow/react-native-tracker/dist/index.d.ts
index d326b4b..c56a6dd 100644
--- a/node_modules/@snowplow/react-native-tracker/dist/index.d.ts
+++ b/node_modules/@snowplow/react-native-tracker/dist/index.d.ts
@@ -29,7 +29,7 @@ declare type ScreenSize = [number, number];
 /**
  * SelfDescribing type
  */
-declare type SelfDescribing = {
+declare interface SelfDescribing<TData extends object> {
     /**
      * Schema
      */
@@ -37,7 +37,7 @@ declare type SelfDescribing = {
     /**
      * Data
      */
-    data: Record<string, unknown>;
+    data: TData;
 };
 /**
  * EventContext type
@@ -547,7 +547,7 @@ declare type ReactNativeTracker = {
      * @param argmap - The self-describing event properties
      * @param contexts - The array of event contexts
      */
-    readonly trackSelfDescribingEvent: (argmap: SelfDescribing, contexts?: EventContext[]) => Promise<void>;
+    readonly trackSelfDescribingEvent: <TData>(argmap: SelfDescribing<TData>, contexts?: EventContext[]) => Promise<void>;
     /**
      * Tracks a screen-view event
      *
@henbrand henbrand changed the title Generic Type for SelfDescribing event Generic type for SelfDescribing event Mar 3, 2022
@matus-tomlein
Copy link
Contributor

matus-tomlein commented Mar 3, 2022

Thanks for the suggestion @henbrand, that's really cool and a good step towards type safety!

It would be awesome if you could make a PR for this. I just have one concern regarding the diff that you sent above – the TData in your code extends object, wouldn't it better to have it extend Record<string, unknown> as previously required by the SelfDescribing type? Perhaps we could take inspiration from the way it's implemented in the Snowplow JavaScript tracker, see here.

@henbrand
Copy link
Contributor Author

henbrand commented Mar 4, 2022

@matus-tomlein - could you give me correct permissions (Direct Access should work) to open a PR?

@matus-tomlein
Copy link
Contributor

@henbrand Can you please fork the repository, make the change and submit a PR to this repository? That should work without needing any extra permissions. Let me know if there is any problem with it.

henbrand added a commit to henbrand/snowplow-react-native-tracker that referenced this issue Mar 4, 2022
@matus-tomlein matus-tomlein changed the title Generic type for SelfDescribing event Add generic type for SelfDescribing event data Mar 7, 2022
@AlexBenny AlexBenny added the type:enhancement New features or improvements to existing features. label Mar 7, 2022
henbrand added a commit to henbrand/snowplow-react-native-tracker that referenced this issue Mar 7, 2022
@matus-tomlein matus-tomlein added this to the Version 1.2.0 milestone Mar 8, 2022
henbrand added a commit to henbrand/snowplow-react-native-tracker that referenced this issue Mar 8, 2022
This was referenced Mar 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:enhancement New features or improvements to existing features.
Projects
None yet
Development

No branches or pull requests

3 participants