Repository navigation
Conversation
The implementation already treats a falsy id as "allocate one from the brokering server", and the doc comment says so, but no declared overload admits an absent id together with options. A caller holding an id of type `string | undefined` - the ordinary shape of an app that persists its peer id across reloads - and a non-default config had to cast. Widening the third overload's `id` describes what the implementation signature already accepts. It is backwards compatible: widening a parameter cannot reject a call that used to compile, `new Peer()` still resolves against the first overload, and `new Peer(options)` still resolves against the second, since PeerOptions is not assignable to `string | undefined`. Closes peers#1370
codeCraft-Ritik
left a comment
There was a problem hiding this comment.
he implementation is solid and directly solves the issue with minimal overhead. The test coverage validates the core path effectively. I noted a couple of minor naming and documentation adjustments in the inline comments, but the functional logic is ready to ship.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1370.
Peer's implementation already accepts an absent id alongside options —constructor(id?: string | PeerOptions, options?: PeerOptions)— and the doc comment says as much: "If no ID is given, one will be generated by the brokering server." But an implementation signature is not callable, and none of the three public overloads admits that combination:So a caller holding an
idof typestring | undefined— an app that persists its peer id across reloads and reuses it, which is the ordinary reason to pass an id at all — together with a non-defaulthost,port,pathorconfig, has to cast:The change
That is the whole diff. No runtime change — this only publishes a capability the implementation already has.
Why it is safe
Widening a parameter cannot reject a call that used to compile, and the new form does not capture calls that belong to another overload:
new Peer()still resolves against overload 1.new Peer(options)still resolves against overload 2 —PeerOptionsis not assignable tostring | undefined.new Peer(id)andnew Peer(id, options)are unchanged.new Peer(undefined)now resolves, and is equivalent tonew Peer().npm run check(tsc --noEmitoverlibande2e),prettier --checkandnpm testall pass.