-
Notifications
You must be signed in to change notification settings - Fork 283
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
Problem with the type declaration of the first parameter of the decode method in index.d.ts? #294
Comments
Unfortunately in JS you can pass anything anywhere. It's not guaranteed it will work, especially if it's not supported by the typescript declaration. The fact that it somewhat works today is an artifact of the past and should not be relied upon. Please don't pass strings to decode method. See https://github.com/ashtuchkin/iconv-lite/wiki/Use-Buffers-when-decoding for details. |
It is true that js has this problem, so why not judge, if it is not Buffer, throw error, and then prompt the developer to only input parameters of type Buffer? |
it might break legacy code |
Look carefully, add one more judgment here, it will not destroy the original code?
|
This will unfortunately break legacy code that is passing strings. |
Problem with the type declaration of the first parameter of the decode method in index.d.ts?
export function decode(buffer: Buffer, encoding: string, options?: Options): string;
The first parameter of decode is declared as Buffer , but it is also possible to pass in string and number, but the correct result is not obtained. This will mislead developers, especially when the string type is used, the implementation code is as follows:
The string is processed by default binary-encoded Buffer, and there is no description in the declaration file. I hope you can modify the declaration file, for example, change it to:
In this way, the developer will clearly know what type of parameters to pass, and also know what the decode method does by default.
The text was updated successfully, but these errors were encountered: