yjs / y-webrtc

WebRTC Connector for Yjs
MIT License
448 stars 109 forks source link

Over-strict type declaration for the options of WebRtcProvider #29

Closed ijdickinson closed 1 year ago

ijdickinson commented 2 years ago

Please save me some time and use the following template. In 90% of all issues I can't reproduce the problem because I don't know what exactly you are doing, in which environment, or which y-* version is responsible. Just use the following template even if you think the problem is obvious.

Checklist

Describe the bug

I'm using TypeScript, and want to pass the URL for a local signaling server to the WebRtcProvider. My code has:

const provider = new WebrtcProvider('testApp', ydoc, { signaling: ['wss://localhost:4444'] })

This produces an error from the TypeScript compiler, because the elements of the peerOpts structure are not marked as optional:

ERROR in src/views/YjsTest.vue:12:57
TS2345: Argument of type '{ signaling: string[]; }' is not assignable to parameter of type 
'{ signaling: string[]; password: string | null; awareness: Awareness; maxConns: number; filterBcConns: 
boolean; peerOpts: any; }'.
  Type '{ signaling: string[]; }' is missing the following properties from type '{ signaling: string[]; 
password: string | null; awareness: Awareness; maxConns: number; filterBcConns: boolean; peerOpts: any; }': 
password, awareness, maxConns, filterBcConns, peerOpts
    10 |
    11 |     const ydoc = new Y.Doc()
  > 12 |     const provider = new WebrtcProvider('dystil', ydoc, { signaling: ['http://localhost:4444'] })
       |                                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

To Reproduce Steps to reproduce the behavior:

  1. Create a skeleton app that creates a WebRtcCompiler
  2. pass the URL of a non-default signalling server
  3. compile with TypeScript
  4. See error

Expected behavior

It should be possible to pass only a subset of the elements of the options, with the non-specified options falling back to their default values

Screenshots

Not applicable

Environment Information

Additional context Add any other context about the problem here.