libp2p / js-peer-info

libp2p Peer abstraction Node.js implementation
https://libp2p.io
MIT License
37 stars 28 forks source link

Add flow type signatures. #62

Open Gozala opened 6 years ago

Gozala commented 6 years ago

As dive into ipfs / libp2p code base I struggle to guess what are all the things passed around. Types as in flow (or typescript for that matter) simplify learning of how things are connected significantly. There for I decided to contribute type signatures to the code base as I digg through it.

What's up with all these .js.flow files ?

Unfortunately flow project has yet to come up with coherent story of how to provide type annotations for third party libraries. In my experience adding .js.flow files works best out of all options, that is because flow type checker when gives a precedent to /path/to/file.js.flow over /path/to/file.js which essentially provides a way to provide type annotations for non-flow typed package such that just using it as dependency will satisfy both type checker and run-time.

It's far from ideal given that .js and .js.flow files can get out of sync but then again unless you're open to adopt flow this is the best option IMO.

Depends on https://github.com/libp2p/js-peer-id/pull/75

dryajov commented 6 years ago

Is there anyway of distributing the typings as a separate package (similar to typescript @type/<package>), so that we don't clutter this package with language specific types?

Gozala commented 6 years ago

Is there anyway of distributing the typings as a separate package (similar to typescript @type/), so that we don't clutter this package with language specific types?

@dryajov there is flow-typed but sadly it's not nearly as good as in typescript and most flow users don't seem to use it for that reason. It is also that there is advantage of having type definitions with implementations as that gives some initiative to library contributors to keep them in sync otherwise they just don't match up (at least that is a big issue with flow-typed) type defs.

@dryajov I think this conversation on how to add types probably should be discussed under https://github.com/ipfs/community/issues/278