-
Notifications
You must be signed in to change notification settings - Fork 27
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be fixed in the JS file. This module is using its npm run generate:types
script to generate the types while do not updated to the new aegir
better to just update to the new ts cmd in aegir |
I am working on updating that as we also need to create declarations for interfaces like Transport. So, the easy way is to unblock bitswap sooner is to keep this setup for now |
I have made following changes:
|
ab2b7d1
to
7fd26cf
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for these changes @Gozala
The class-is
has also been problematic for me trying to integrate the transport interface and the connection. So, I agree we should follow what has been done and remove it.
The changes seem good to me, but there are a few pubsub things that we should change. I tried out this branch with https://github.com/ChainSafe/js-libp2p-gossipsub which uses this interface types and got some problems:
ts/index.ts:69:7 - error TS2415: Class 'Gossipsub' incorrectly extends base class 'PubsubBaseProtocol'.
Property '_addPeer' is private in type 'PubsubBaseProtocol' but not in type 'Gossipsub'.
69 class Gossipsub extends Pubsub {
~~~~~~~~~
ts/index.ts:146:11 - error TS2345: Argument of type '{ scoreParams: PeerScoreParams; scoreThresholds: PeerScoreThresholds; emitSelf: boolean; gossipIncoming: boolean; fallbackToFloodsub: boolean; ... 14 more ...; libp2p: Libp2p; }' is not assignable to parameter of type '{ debugName: string; multicodecs: string | string[]; libp2p: any; globalSignaturePolicy: { StrictSign: "StrictSign"; StrictNoSign: string; } | undefined; canRelayMessage: boolean | undefined; emitSelf: boolean | undefined; }'.
Property 'canRelayMessage' is missing in type '{ scoreParams: PeerScoreParams; scoreThresholds: PeerScoreThresholds; emitSelf: boolean; gossipIncoming: boolean; fallbackToFloodsub: boolean; ... 14 more ...; libp2p: Libp2p; }' but required in type '{ debugName: string; multicodecs: string | string[]; libp2p: any; globalSignaturePolicy: { StrictSign: "StrictSign"; StrictNoSign: string; } | undefined; canRelayMessage: boolean | undefined; emitSelf: boolean | undefined; }'.
146 super({
~
147 debugName: 'libp2p:gossipsub',
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...
150 ...opts
~~~~~~~~~~~~~
151 })
~~~~~
node_modules/libp2p-interfaces/src/pubsub/index.d.ts:38:9
38 canRelayMessage: boolean | undefined;
~~~~~~~~~~~~~~~
'canRelayMessage' is declared here.
ts/index.ts:301:21 - error TS2341: Property '_addPeer' is private and only accessible within class 'PubsubBaseProtocol'.
301 const p = super._addPeer(peerId, protocol)
~~~~~~~~
ts/index.ts:328:31 - error TS2341: Property '_removePeer' is private and only accessible within class 'PubsubBaseProtocol'.
328 const peerStreams = super._removePeer(peerId)
The errors seem related to _addPeer
, _ removePeer
being private now (they are extended in gossipsub), as well as the option canRelayMessage
not being declared in gossipsub and lost the optional sign.
These things can also be updated in gossipsub, but I was trying to avoid a breaking change at this moment, until we finalize the types for the interface.
What do you think? Can we easily revert this pubsub types without blocking bitswap?
I don't think those are changes that I've made it's just new typescript is recognizing |
It should be because of the build. Also not sure, but if protected solves this issue, let's go with it for now 👍 |
@vasco-santos I have changed all I have also created a type definition for the |
5617238
to
46c98e9
Compare
This solves the functions issue, thanks 👌
Getting these two errors now. Seem related to that, right?
Other than that, did we have any decision to put typedef on the end of the file? I remember seeing that discussion on a PR and I thought we would go with the typedefs on top of the file. I also synced with jacob about following that pattern in libp2p land |
I believe we have converged on putting them at the end instead of top. More details on the proposed approach we plan on using is here ipfs/js-ipfs#3413 |
Done in #74 |
Without this change ipfs/js-ipfs-bitswap#261 fails type-check with a following error:
That is because typedefs claim that exported value is an instance of
MulticodecTopology
while it actually exports the class.min
andmax
are also optionals.