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

[Bug]: incorrect type signatures on Hash's digest and update methods #9484

Open
dinofx opened this issue Feb 27, 2025 · 0 comments
Open

[Bug]: incorrect type signatures on Hash's digest and update methods #9484

dinofx opened this issue Feb 27, 2025 · 0 comments

Comments

@dinofx
Copy link

dinofx commented Feb 27, 2025

System Info

macOS

Details

The Hash class' digest and update methods are incorrect. They are ambiguous and should use overloads like the node type declarations do.

The existing signatures are:

update(data: string | Buffer, inputEncoding?: string): this {
throw new AbstractMethodError();
}

digest(encoding?: string): string | Buffer {
throw new AbstractMethodError();
}

Using overloaded signatures makes it clear when the inputEncoding is required, and when the return value will be a string vs. buffer. The correct signatures would be something like:

update(data: string, inputEncoding: string): this;
update(data: Buffer): this;
update(data: string | Buffer, inputEncoding?: string): this {
...

digest(): Buffer;
digest(encoding: string): string;
digest(encoding?: string): string | Buffer {
...

Reproduce link

No response

Reproduce Steps

In a loader, do something like:

const hash = this.utils.createHash('md5').update(buffer).digest('hex');

The call to update suggests that a second param can be passed, but this isn't true for buffers. And the type of hash above is ambiguously string | Buffer, when it is guaranteed to be string since an encoding was provided.

@dinofx dinofx added the pending triage The issue/PR is currently untouched. label Feb 27, 2025
@chenjiahan chenjiahan added PR welcome and removed pending triage The issue/PR is currently untouched. labels Feb 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants