versatica / mediasoup-client-aiortc

mediasoup-client handler for aiortc Python library
https://mediasoup.org
ISC License
56 stars 30 forks source link

TypeScript error in FakeRTCDataChannel #24

Open ibc opened 1 year ago

ibc commented 1 year ago
src/FakeRTCDataChannel.ts:23:14 - error TS2420: Class 'FakeRTCDataChannel' incorrectly implements interface 'RTCDataChannel'.
  Types of property 'addEventListener' are incompatible.
    Type '{ <T extends string>(type: T, callback?: EventListener<this, Event<string>> | null | undefined, options?: AddOptions | undefined): void; (type: string, callback?: EventListener<...> | ... 1 more ... | undefined, options?: AddOptions | undefined): void; <T extends string>(type: T, callback: EventListener<...> | ... 1...' is not assignable to type '{ <K extends keyof RTCDataChannelEventMap>(type: K, listener: (this: RTCDataChannel, ev: RTCDataChannelEventMap[K]) => any, options?: boolean | ... 1 more ... | undefined): void; (type: string, listener: EventListenerOrEventListenerObject, options?: boolean | ... 1 more ... | undefined): void; }'.
      Types of parameters 'callback' and 'listener' are incompatible.
        Type '(this: RTCDataChannel, ev: any) => any' is not assignable to type 'EventListener<this, Event<string>> | null | undefined'.
          Type '(this: RTCDataChannel, ev: any) => any' is not assignable to type 'CallbackFunction<this, Event<string>>'.
            The 'this' types of each signature are incompatible.
              Type 'this' is not assignable to type 'RTCDataChannel'.
                Type 'FakeRTCDataChannel' is not assignable to type 'RTCDataChannel'.
                  Types of property 'addEventListener' are incompatible.
                    Type '{ <T extends string>(type: T, callback?: EventListener<this, Event<string>> | null | undefined, options?: AddOptions | undefined): void; (type: string, callback?: EventListener<...> | ... 1 more ... | undefined, options?: AddOptions | undefined): void; <T extends string>(type: T, callback: EventListener<...> | ... 1...' is not assignable to type '{ <K extends keyof RTCDataChannelEventMap>(type: K, listener: (this: RTCDataChannel, ev: RTCDataChannelEventMap[K]) => any, options?: boolean | ... 1 more ... | undefined): void; (type: string, listener: EventListenerOrEventListenerObject, options?: boolean | ... 1 more ... | undefined): void; }'.
                      Types of parameters 'callback' and 'listener' are incompatible.
                        Type '(this: RTCDataChannel, ev: any) => any' is not assignable to type 'EventListener<this, Event<string>> | null | undefined'.

23 export class FakeRTCDataChannel extends EventTarget implements RTCDataChannel

This is currently "workarounded" with a @ts-ignore above FakeRTCDataChannel class definition and also another 2 @ts-ignore in Handler.ts, which is hell ofc.

Problem is that mediasoup-client relies on "dom" TS library, and here we are defining FakeRTCDataChannel which uses event-target-shim dep to mimics DOM's EventTarget. Related task in mediasoup-client: https://github.com/versatica/mediasoup-client/issues/279