microsoft / TypeScript-DOM-lib-generator

Tool for generating dom related TypeScript and JavaScript library files
Apache License 2.0
600 stars 417 forks source link

RTCPeerConnection.addIceCandidate cannot be called with `null` #1738

Open silverlyra opened 3 weeks ago

silverlyra commented 3 weeks ago

In WebRTC, the icecandidate event’s candidate property is either “an RTCIceCandidate object … or null to indicate that there are no further candidates”. This currently has the correct type in dom.d.ts:

interface RTCPeerConnectionIceEvent extends Event {
    readonly candidate: RTCIceCandidate | null;
}

null has the same special meaning on the receiver side of the ICE gathering process. The addIceCandidate is used both to submit a candidate from the remote peer, or to convey the end-of-candidates signal “[i]f no candidate object is specified, or its value is null”.

But it’s not currently valid to pipe a null from the icecandidate event to addIceCandidate:

interface RTCPeerConnection extends EventTarget {
    addIceCandidate(candidate?: RTCIceCandidateInit): Promise<void>;
}

error TS2345: Argument of type null is not assignable to parameter of type RTCIceCandidateInit | undefined