-
Notifications
You must be signed in to change notification settings - Fork 39
feat: add flow typedefs #79
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[ignore] | ||
|
||
[include] | ||
|
||
[libs] | ||
|
||
[lints] | ||
|
||
[options] | ||
|
||
[strict] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// @flow strict | ||
|
||
export type Version = 0 | 1 | ||
export type Codec = string | ||
export type Multihash = Buffer | ||
export type BaseEncodedString = string | ||
|
||
declare class CID<a> { | ||
constructor(Version, Codec, Multihash): void; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CID now takes an optional There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
constructor(BaseEncodedString): void; | ||
constructor(Buffer): void; | ||
|
||
+codec: Codec; | ||
+multihash: Multihash; | ||
+buffer: Buffer; | ||
+prefix: Buffer; | ||
|
||
toV0(): CID<a>; | ||
toV1(): CID<a>; | ||
toBaseEncodedString(base?: string): BaseEncodedString; | ||
toString(): BaseEncodedString; | ||
toJSON(): { codec: Codec, version: Version, hash: Multihash }; | ||
|
||
equals(mixed): boolean; | ||
|
||
static codecs: { [string]: Codec }; | ||
static isCID(mixed): boolean; | ||
static validateCID(mixed): void; | ||
} | ||
|
||
export default CID | ||
export type { CID } |
There was a problem hiding this comment.
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?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, they are not required
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 nodea
which in turn would allowget(CID<a>):Promise<a>
without type parametera
it wouldn’t be possible to express that type of relationship.There was a problem hiding this comment.
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 parameterThere was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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