-
Notifications
You must be signed in to change notification settings - Fork 5.6k
fix(std/node): fix readFile types, add encoding types: fix #6450 #6451
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
Conversation
} | ||
const buffer = maybeDecode(data, encoding); | ||
(cb as BinaryCallback)(null, buffer); | ||
}).catch((err) => cb && cb(err)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this could be changed from }).catch((err) => cb && cb(err));
to }).catch((err) => cb!(err));
as for some reason, the type checker is not considering the if statement - if it is the type checker's fault, I can do the change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - thanks!
This PR corrects the node readFile types. See #6450 for the bug report. It is ready for review and at your discretion merging.
In short:
null | undefined
This PR corrects these issues, and includes new type information for binary and text encodings such that methods can be overloaded accordingly to resolve the correct types depending on the inputs.
There was also another issue, where there was an encoding type
buffer
defined, however that does not exist in Node.js, and I couldn't find any usages of it within Deno either. It seemed it was meant to bebinary
(an encoding that returns a Buffer instance), so I changed it accordingly and added a comment.promises.readFile
node
deno before
deno after
readFile
node
deno before
deno after
readFileSync
node
deno before
deno after
Tests have been updated accordingly. Static type checks in the tests capture this.