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

Commit

Permalink
docs: Explain CID type parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
Gozala committed Apr 16, 2019
1 parent 19cd945 commit f16acec
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ export type SerializedCID = {
* , as defined in [ipld/cid](https://github.com/multiformats/cid).
* @class CID
*/
// CID<a> is generic and type parameter `a` represents type of the data that
// the CID addresses. While type parameter is not really used in this library
// it is still useful in enabling other libraries to encode type information
// e.g. it is possible to define functions like:
// function get <a>(CID<a>):Promise<a>
// function put <a>(a):Promise<CID<a>>
// Which would allow type-checker to infer type of the following value:
// const cid = await put({ x: 1, y: 2 })
// ...
// const point = await get(cid)
// point.x //:number
// point.z //:Cannot get `point.z` because property `z` is missing in object literal { x: 1, y: 2 }.
class CID /*:: <a> */{
/**
* Create a new CID.
Expand Down

0 comments on commit f16acec

Please sign in to comment.