Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update event type to extend { [s: string]: any } #336

Merged
merged 2 commits into from
Sep 22, 2022

Conversation

achingbrain
Copy link
Collaborator

@achingbrain achingbrain commented Sep 20, 2022

The Events type has to extend { [s: string]: any }. Hopefully one day TS will ship a typed EventEmitter and this won't be necessary any more.

Fixes a type error:

[10:45:49] tsc [started]
test/utils/events.ts:64:25 - error TS2344: Type 'Events' does not satisfy the constraint '{ [s: string]: any; }'.

64   emitter: EventEmitter<Events>,
                           ~~~~~~

  test/utils/events.ts:63:35
    63 export const awaitEvents = async <Events = GossipsubEvents>(
                                         ~~~~~~~~~~~~~~~~~~~~~~~~
    This type parameter might need an `extends { [s: string]: any; }` constraint.


Found 1 error in test/utils/events.ts:64

The `Events` type has to extend `{ [s: string]: any }`. Hopefully one
day TS will ship a typed `EventEmitter` and this won't be necessary
any more.
@achingbrain achingbrain requested a review from a team as a code owner September 20, 2022 09:45
@achingbrain
Copy link
Collaborator Author

Build is failing with

Error: R] No matching export in "dist/src/message/rpc.cjs" for import "default"

    dist/src/message/rpc.js:1:7:
      1 │ import cjs from "./rpc.cjs";

This looks related to the removal of protons and switch back to protobufjs - @tuyennhv any idea why this has started failing to build?

@dapplion
Copy link
Contributor

Build is failing with

it also breaks for me

@twoeths
Copy link
Contributor

twoeths commented Sep 22, 2022

@achingbrain now it's failing with another error

Error: src/index.ts(511,68): error TS2345: Argument of type 'import("/home/runner/work/js-libp2p-gossipsub/js-libp2p-gossipsub/node_modules/@multiformats/multiaddr/dist/src/index").Multiaddr[]' is not assignable to parameter of type 'import("/home/runner/work/js-libp2p-gossipsub/js-libp2p-gossipsub/node_modules/@libp2p/interface-connection/node_modules/@multiformats/multiaddr/dist/src/index").Multiaddr[]'.

I think we need to change the way to import from protobuf, will revisit this issue after we fix the above

@achingbrain
Copy link
Collaborator Author

achingbrain commented Sep 22, 2022

@tuyennhv you can merge #339 to fix the multiaddr error.

@twoeths
Copy link
Contributor

twoeths commented Sep 22, 2022

@achingbrain I merged the PR for multiaddr type.

Regarding this error, root cause is

This file is considered to be an ECMAScript module because of the "export" keyword here:

    dist/src/message/rpc.cjs:1747:0:
      1747 │ export {};

somehow rpc.cjs added this at the end of the line so the file becomes an es module

export {};

do you know why that line is added during the build process?

@achingbrain
Copy link
Collaborator Author

Not off the top of my head, no. TBH I've got rid of mixed CJS/ESM/TS files and only use protobuf.js via protons everywhere else in the stack because debugging these sorts of tooling clashes is a frequent and painful activity otherwise.

@mpetrunic
Copy link
Member

Not off the top of my head, no. TBH I've got rid of mixed CJS/ESM/TS files and only use protobuf.js via protons everywhere else in the stack because debugging these sorts of tooling clashes is a frequent and painful activity otherwise.

Isn't protons now some in speed as protobuf.js?

@twoeths
Copy link
Contributor

twoeths commented Sep 22, 2022

Not off the top of my head, no. TBH I've got rid of mixed CJS/ESM/TS files and only use protobuf.js via protons everywhere else in the stack because debugging these sorts of tooling clashes is a frequent and painful activity otherwise.

Isn't protons now some in speed as protobuf.js?

@mpetrunic it's quite comparable to protobuf but not stable enough from the last time I tried, there's a draft PR for it #327

@achingbrain
Copy link
Collaborator Author

achingbrain commented Sep 22, 2022

The weird thing in all that is that it uses protobuf.js internally for all serialization/deserialization now so it should be comparable.

It basically just outputs a nice easily-compilable ts interface to the data object created from a .proto file.

It does use a more recent version of protobuf.js than this module, so that might be a thing.

@twoeths
Copy link
Contributor

twoeths commented Sep 22, 2022

I'd test protons version of gossipsub in lodestar before merging that PR as performance is very important to lodestar, right now it's blocked by ChainSafe/lodestar#4114

cc @wemeetagain

@twoeths
Copy link
Contributor

twoeths commented Sep 22, 2022

merging the PR as it happens in https://github.com/ChainSafe/js-libp2p-gossipsub/actions/runs/3103234285/jobs/5026341160

there should be another build issue regarding rpc.cjs file

@twoeths twoeths merged commit 5c0db52 into ChainSafe:master Sep 22, 2022
@achingbrain achingbrain deleted the fix/types branch September 22, 2022 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants