Skip to content
This repository has been archived by the owner on Sep 3, 2021. It is now read-only.

feat: add flow typedefs #79

Merged
merged 1 commit into from
Apr 4, 2019
Merged

feat: add flow typedefs #79

merged 1 commit into from
Apr 4, 2019

Conversation

Gozala
Copy link
Contributor

@Gozala Gozala commented Apr 4, 2019

Add flow type definitions which would improve workflow for dependent libraries that happen to use flow type-checker.

This just index.js.flow is what flow would resolve to when imported module resolves to index.js and there for dependencies of this library will be able to infer type info.

Add flow type definitions which would improve workflow for dependent libraries that happen to use flow type-checker.
@mikeal
Copy link
Contributor

mikeal commented Apr 4, 2019

I don’t know enough about flow to know if this is correct or not so I’ll just trust that you did it correctly and merge it :)

@mikeal mikeal merged commit a75da83 into multiformats:master Apr 4, 2019
@mikeal
Copy link
Contributor

mikeal commented Apr 4, 2019

whoops! my bad, I thought this was a different repo cause we were talking about this same thing there. I should not have merged this before others had reviewed it.

can we get some +1’s here and if people have objections i can back it out.

export type BaseEncodedString = string

declare class CID<a> {
constructor(Version, Codec, Multihash): void;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CID now takes an optional multibaseName string as the 4th param as of #77

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing that out @olizilla, I'll create a followup pull to add that param.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@olizilla @mikeal Can I assume that there is a consensus on wanting to keep the typedefs though ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if there's consensus, but I'm the lead maintainer and I'd like to keep them :)

Copy link
Contributor Author

@Gozala Gozala Apr 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vmx I think @mikeal was just looking +1 from someone, and it sounds like we have one. Thanks

export type Multihash = Buffer
export type BaseEncodedString = string

declare class CID<a> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Gozala generics aren't a requirement for class defs are they? I don't see a being used in CID and am not sure how CID could be a generic container so does <a> mean something else here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Gozala generics aren't a requirement for class defs are they?

Correct, they are not required

I don't see a being used in CID and am not sure how CID could be a generic container so does mean something else here?

On my phone so can’t provide links but this is related to our other discussions on decode / encode. CID<a> implies here that it’s address for node a which in turn would allow get(CID<a>):Promise<a> without type parameter a it wouldn’t be possible to express that type of relationship.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be more specific: indeed a type param is not used here, but it’s there because users of this lib are expected to make use of that parameter

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, wow, that's pretty funky. So tools that use flow definitions would follow that all the way through such a call chain and enforce that, or is this simply for the sake of descriptive completeness?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flow type-checker will indeed catch and report any miss-matches.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW that’s also a weak point of TS (at least it was) as it throws away unused type parameters not used in the class / function definitions while flow keeps them for inference at call-sites. It may not seem that important but in practice it makes a huge difference

@alanshaw
Copy link
Member

alanshaw commented Apr 9, 2019

This was planned over a year ago ipfs/js-ipfs#1260 but seems to have stalled until now. @vmx are you planning on working on it this quarter?

@vmx
Copy link
Member

vmx commented Apr 9, 2019

No real plan to work on it, but somehow I got dragged into this and as I'm still in favour of it (though this time less intrusive with using the inline comment style) I think I'll spend some time on it.

@Gozala
Copy link
Contributor Author

Gozala commented Apr 9, 2019

somehow I got dragged into this

@vmx I’m sorry

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants