I am running into TypeScript errors when working in my Expo/React Native project.
The Problem
Whenever I try to ad event listeners to either RTCPeerConnection or RTCDataChannel, TypeScript says that the property doesn’t exist.
Property 'addEventListener' does not exist on type 'RTCPeerConnection'.
Property 'addEventListener' does not exist on type 'RTCDataChannel'.
Example
const pc = new RTCPeerConnection(config);
pc.addEventListener("icecandidate", (event) => { ... }); // TS error
const dc = pc.createDataChannel("label");
dc.addEventListener("message", (event) => { ... }); // TS error
What I’ve Tried
- These methods do work. I followed [react-native-webrtc/Documentation/CallGuide.md at master · react-native-webrtc/react-native-webrtc · GitHub](https://react-native-webrtc call guide)
- I’ve tried creating a type augmentation file to extend the types which fixed the error for RTCDataChannel, but then I started getting new type errors for the event objects in the handlers.
My Setup
- Expo SDK 53.0.11
- react-native-webrtc: 124.0.5
- typescript 5.8.3
Questions
- Is anyone else having these issues? If so, did you also create additional type augmentation files to extend the types?
- If not, how are you accessing the type declarations for these event listeners and event objects?
- Is there a recommended way to get TypeScript to recognize these event listener methods and event types in react-native-webrtc?
Any help or pointers would be greatly appreciated!