rudderlabs / rudder-sdk-react-native

Repository for RudderStack's React Native SDK - to track your event data via RudderStack.
https://www.rudderstack.com
Other
17 stars 18 forks source link

AnonymousID typescript and safe access error #355

Closed connorpmullins closed 5 months ago

connorpmullins commented 5 months ago

Hi there, I'm working in a react native project using version 1.13.1 of the "@rudderstack/rudder-sdk-react-native" SDK.

ISSUE: In the below code you can see a red typescript warning image

The error is that Type 'unknown' is not assignable to type 'string'.

PROPOSED SOLUTION:

EXTRA REQUEST:

1abhishekpandey commented 5 months ago

Hey @connorpmullins,

I understand that you want a better way to fetch the anonymousId.

However, any value you set by calling our identify API is stored in traits. Since users can pass various types (String, Integer, Objects, etc.), we have defined the traits type as Record<string, unknown>. Therefore, it's not possible for us to change that.

As a temporary workaround, you can convert that value to a String.

A better solution would be for us to introduce a getAnonymousId API, which will return the anonymousId as a string. This API can be called after the SDK is initialized. I can forward this request to our team, and we will ensure to implement it in the future.

Please let me know if you have any further questions!

connorpmullins commented 5 months ago

Thanks @1abhishekpandey !

Super helpful - mind updating here if/when getAnonymousId gets implemented?

Thank you!