Skip to content

fix: Improve Hash.digest(encoding) TypeScript return type#964

Merged
boorad merged 2 commits intomargelo:mainfrom
fredikey:main
Mar 9, 2026
Merged

fix: Improve Hash.digest(encoding) TypeScript return type#964
boorad merged 2 commits intomargelo:mainfrom
fredikey:main

Conversation

@fredikey
Copy link
Contributor

@fredikey fredikey commented Mar 6, 2026

Summary

This PR improves TypeScript typings in src/hash.ts (no runtime behaviour changes)

1) Fix Hash.digest(encoding) return type

Hash.digest(encoding) is typed as Buffer, but it returns a string when encoding param is provided

createHash(...).update(...).digest('base64') // returns Buffer type, not a string type

This appears to be a typo, cuz similar APIs in this package (Blake3.digest() and Hmac.digest()) return string type when encoding is provided

2) Improve hash() return type precision

Added overloads for hash() function, so return type depends on outputEncoding:

  • hash(algorithm, data, outputEncoding) -> string
  • hash(algorithm, data) -> Buffer

Before, the return type was always string | Buffer

Copy link
Collaborator

@boorad boorad left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

thanks!

@boorad boorad merged commit 5ea5518 into margelo:main Mar 9, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants