Giter Club home page Giter Club logo

Comments (8)

GregTheGreek avatar GregTheGreek commented on June 15, 2024

Whats the status on this? Should we wait until we chat with the libp2p2 team?

from js-libp2p-gossipsub.

Mikerah avatar Mikerah commented on June 15, 2024

I think we should wait until the chat with the libp2p team. I will contact Raul again to see what their availability is on their end.

from js-libp2p-gossipsub.

Mikerah avatar Mikerah commented on June 15, 2024

During the call, there were several ideas about how to go about this. For now, we will be making bindings for gossipsub and potentially in the future, make them for libp2p.

from js-libp2p-gossipsub.

raulk avatar raulk commented on June 15, 2024

The issue was that as soon as you begin typing a module, you realise that that module likely uses classes or objects from another module (e.g. switch, connection manager, etc.), which ideally would be typed as well.

To avoid galavanting around all of libp2p typing everything at once, you can either use any, object, or type the element locally with only the methods and properties you are using from within gossipsub.

EDIT: As you eventually make your way around the codebase, the types you define at the origin sites will be supersets of the local types at call site, so they can easily subsume those without causing breakage.

from js-libp2p-gossipsub.

raulk avatar raulk commented on June 15, 2024

^^ let me know if you need an example of the above. Feels kinda abstract.

from js-libp2p-gossipsub.

Mikerah avatar Mikerah commented on June 15, 2024

If we type the element using any or object, I think that defeats the purpose of using types and we don't get the "built-in" documentation that using TypeScript provides. By locally typing elements, do you mean something like this?

from js-libp2p-gossipsub.

raulk avatar raulk commented on June 15, 2024

That's an interesting approach that's enabled by typeRoots. That could definitely work -- and in fact we can go over those types at the Polkadot repo and revise them in order to, eventually, add them to the corresponding repos at libp2p.

What I had in mind was something like this. Imagine an index.d.ts file in this repo's root (names are all made up examples):

declare module 'js-libp2p-switch' {
   interface libp2pswitch {
     // lazily declare only the methods and fields you use.
     methodA(): typeA;
     methodB(): typeB;
     readonly fieldC: typeC;
   }
}

class GossipSub {
  static public readonly switch: libp2pswitch;
  subscribe(topic: string): Result;
}

But yeah, I agree that placing the ambient declarations for each imported module in a file of its own, and linking it via typeRoots is probably cleaner and better scoped.

On a related note, let's try and converge our types with Polkadot's!

from js-libp2p-gossipsub.

GregTheGreek avatar GregTheGreek commented on June 15, 2024

Closing since its stale

from js-libp2p-gossipsub.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.