Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add hasCode to Digest #308

Merged
merged 1 commit into from
Sep 16, 2024
Merged

Conversation

achingbrain
Copy link
Member

To give a hint to tsc that a MultihashDigest has a specific code, add a disambiguator hasCode function.

This lets us define functions that require a certain multihash code with type saftey.

To give a hint to tsc that a `MultihashDigest` has a specific code,
add a disambiguator `hasCode` function.

This lets us define functions that require a certain multihash code
with type saftey.
@@ -1,7 +1,7 @@
import { coerce } from '../bytes.js'
import * as Digest from './digest.js'

const code = 0x0
const code: 0x0 = 0x0
Copy link
Member Author

@achingbrain achingbrain Sep 13, 2024

Choose a reason for hiding this comment

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

This is necessary otherwise the type of code is derived as number and not 0 which means digestHasCode(hash, identity.code) hints that the type of hash is MultihashDigest<number> when we want it to be MultihashDigest<0x0>.

digestHasCode(hash, 0x0) works without this change but it'd be nice to be able to reuse identity.code.

@achingbrain achingbrain merged commit a5fbf61 into master Sep 16, 2024
19 checks passed
@achingbrain achingbrain deleted the feat/add-has-code-to-digest branch September 16, 2024 06:43
github-actions bot pushed a commit that referenced this pull request Sep 16, 2024
## [13.3.0](v13.2.4...v13.3.0) (2024-09-16)

### Features

* add hasCode to Digest ([#308](#308)) ([a5fbf61](a5fbf61))
Copy link

🎉 This PR is included in version 13.3.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

2 participants