Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Enable type-checker support in js-ipfs and js-libp2p #2320

Closed
@Gozala

Description

@Gozala

Hi Folks,

Lately I have being trying to use js-ipfs in a project and got somewhat overwhelmed by amount of libraries at play, don’t get me wrong, I like the seperation of concerns this layered setup provides, it’s just incredibly hard to pin down what are the things being passed around and I’ve being following a rabbit hole for multiple days now. I also noticed the pattern across the stack where there are defined interfaces like transports and ipdl-resolvers, etc... and multiple implementations of them.

This got me thinking that it would be exteremly helpful if those interfaces were not just written out in markdown but were typed as flow (or typescript) interfaces than implementation could in fact declare that class / object implements it and type checker will make sure that is the case.

As I have being struggling to understand shapes of things being passed around (argument types, return types) I really started wishing those were tyoe annotated as that would have saved me so much time jumping across libraries to look things up. In fact I noticed that I had to look same things multiple times because as I kept going amount of info overflowed my mental capacity. That is yet another time where I wished type signatures were available as that would allowed my editor to just tell me what the interfaces is without following dependency chain and looking things up. In fact it got so difficult that I end up writing type signatures myself to save time redoing same lookups over and over.

Another controversial but still argument worth making is that there have type checker help make API’s clearer and lmby consequence easier for users. For instance I encountered a function that either takes protocol and buffer and returns string or takes protocol and string and returns buffer, it’s cool but consequently margin for error is higher + has runtime costs. Once you start using type system it navigates you towards less ambiguous API as concrete return types save you from type refinements down the line.

I also noticed multiple cases of polymorphic APIs where funtion needs to match over the type of argument and those checks are somewhat optimistic (as in no guarantee that argument is actually implements expected interface) that is another area where type checker like flow would greatly help. It provides a specific way to refine types and provides guarantees that with in the refined block value implements interface of that type it also ensures that no variant is being overlooked (meaning that each variant of argument type us handled).

Metadata

Metadata

Assignees

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions