Description
Thank you for adding React Native support for this library! I am starting on integrating Segment into my React Native project and am using analytics-react-native
. I just added Typewriter v8, and it is working great, except it only generates types for events that have custom properties. Here are my observations for events that have no custom properties:
- These events do show up in the
rules
array inplan.json
jsonSchema.properties
is{}
as expected. - in
segment.tsx
, there is no mention whatsoever of these events:- the interface is not generated
- the
extendedClient.myCustomEvent = () => ...
function is not created inextendSegmentClient
I've verified that if I go into Segment and add even a single property to the event and then rerun npx typewriter -u
, or if I just manually add properties to plan.json
, the events are added to segment.tsx
as expected.
Proposed solution
Ideally, if I had an event called My Custom Event
that takes no properties, something like the following would be generated in segment.tsx
:
// generated segment.tsx
export type MyCustomEvent = undefined
// alternatively: export type MyCustomEvent = Record<string, never> | undefined
...
// this part is the same as for other events
extendedClient.myCustomEvent = (message: MyCustomEvent) => {
client.track('My Custom Event', message as unknown as JsonMap)
}
The second argument of client.track
is already typed to accept undefined, so this doesn't result in any errors with the client or TypeScript.
Here is my typewriter.yml
:
client:
language: typescript
sdk: analytics-react-native
languageOptions: {}
trackingPlans:
- id: my_tracking_plan_id
path: src/__generated__
I'd be happy to take a pass at fixing this and opening a PR but might need a bit of help getting pointed in the right direction. Thanks again for this library! 🙂
Steps to reproduce
- Initialize typewriter using the React Native defaults (or use the shared config file above)
- Set up a Segment event that has no custom properties
- Run
npx typewriter
ornpx typewriter -u
- The new event will not be included in the generated
segment.tsx
Versions
- typewriter/8.0.10 darwin-arm64 node-v18.9.0
- @segment/analytics-react-native@2.10.1
- @segment/sovran-react-native@0.4.5
- MacOS Ventura 13.0.1