Open alex-a-pereira opened 2 days ago
If anyone else runs into this issue this is how I fixed in my codebase temporarily:
Using patch-package
make this patch so TS will fail to compile if I don't account for the typings
diff --git a/node_modules/@iterable/react-native-sdk/js/IterableInAppMessage.d.ts b/node_modules/@iterable/react-native-sdk/js/IterableInAppMessage.d.ts
index b363e19..41efec4 100644
--- a/node_modules/@iterable/react-native-sdk/js/IterableInAppMessage.d.ts
+++ b/node_modules/@iterable/react-native-sdk/js/IterableInAppMessage.d.ts
@@ -19,7 +19,7 @@ declare class IterableInAppMessage {
/**
* when was this message created
*/
- readonly createdAt?: Date;
+ readonly createdAt?: string | number | Date;
/**
* when to expire this in-app (undefined means do not expire)
*/
Then I made a helper function in my code
const parseDateFromUnknownFormat = (iterableDate: string | number | Date | undefined): Date | null => {
if (iterableDate == null) { return null }
if (typeof iterableDate === 'string') {
return new Date(parseInt(iterableDate))
}
if (typeof iterableDate === 'number') {
return new Date(iterableDate)
}
return iterableDate
}
Thanks for reporting this issue @alex-a-pereira ! and appreciate the workaround suggested for fellow developers. Will have this issue flagged internally for the team to fix.
Issue
The type is declared to be a
Date
(potentially undefined)However when i add the following logging:
I see that
typeof createdAt
is astring
when logging from Android and a Number when logging from iOSAndroid logs: i included the error that is thrown that's causing my app to crash (android only)
iOS Logs
Investigation (so far)
I'm not sure what is causing the typeof to be different between iOS/Android, however by reading the code it doesn't look like the typing of
Date | undefined
is correct.dateObject.setUTCMilliseconds
returns aNumber
, not aDate