multiformats / js-cid

CID implementation in JavaScript
MIT License
98 stars 39 forks source link

fix: types to align with multicodec api #138

Closed Gozala closed 3 years ago

Gozala commented 3 years ago

Added types in multicodec introduces issue in js-ipfs when using multicodec.getName(cid.code) because cid.code was entyped as number while getName expects CodecNumber that is subset of number.

This change addresses that issue by changing code type accordingly & updating codec type to also fix multicodec.getNumber(cid.codec).

I also have noticed that generated types had bunch fields version, codec and multihash types generated as any, that is because constructor has early returns so type annotations at the end of the constructor were ignored. This pull fixes that by moving those annotations at the top of the file instead.