binaryminds / react-native-sse

Event Source implementation for React Native. Server-Sent Events (SSE) for iOS and Android 🚀
https://www.npmjs.com/package/react-native-sse
MIT License
175 stars 27 forks source link

Custom Event Emit Type as Open Event #8

Closed Tim4497 closed 8 months ago

Tim4497 commented 2 years ago

When I try the example with custom events I get:

es.addEventListener("ping", (event) => { console.log("Received ping with data:", event.data); });

Property 'data' does not exist on type 'EventSourceEvent | CustomEvent<MyCustomEvents>'. Property 'data' does not exist on type 'OpenEvent'.ts(2339)

wojciechkrol commented 2 years ago

Hello @Tim4497!

Thank you! I'm working on it.

pke commented 1 year ago

Ran into the same problem. TS does not seem to be able to deduct the type correctly. One needs to specify event.type === "ping" && event.data together to make the TS compiler happy. @binaryminds Any ideas how to solve this?

wojciechkrol commented 8 months ago

Please take a look at this PR https://github.com/binaryminds/react-native-sse/pull/29 and let me know if it does resolve this problem.