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

Allow passing undefined options to move() #947

Closed
Nokel81 opened this issue Mar 15, 2022 · 3 comments · Fixed by #955
Closed

Allow passing undefined options to move() #947

Nokel81 opened this issue Mar 15, 2022 · 3 comments · Fixed by #955

Comments

@Nokel81
Copy link

Nokel81 commented Mar 15, 2022

  • **Operating System:**macos
  • **Node.js version:**14.18.3
  • **fs-extra version:**10.0.1

The follow code:

const { move } = require("fs-extra");

move("/some/path/that/exists", "some/path/that/doesnt/exist", undefined)
  .then(() => console.log("success")
  .catch(console.error);

produces the following type error: TypeError: Cannot read property 'overwrite' of undefined

The error seems to be from the handling of optional callback and optional options on line 12-15 of lib/move/move.js

@RyanZim
Copy link
Collaborator

RyanZim commented Mar 15, 2022

Right, both callback and options are optional; you're passing undefined, which it doesn't know how to deal with. If you don't want to specify options or a callback, omit the argument altogether.

@RyanZim RyanZim closed this as completed Mar 15, 2022
@Nokel81
Copy link
Author

Nokel81 commented Mar 15, 2022

Yes but in JS passing undefined as a parameter should mean the same as not passing it. And if I am making a wrapper around your method then I shouldn't have to check if the optional field is not passed in.

For instance with default params, passing undefined means "use default".

@RyanZim
Copy link
Collaborator

RyanZim commented Mar 16, 2022

Ah, true; this does make wrappers inconvenient. PR welcome to fix.

@RyanZim RyanZim reopened this Mar 16, 2022
@RyanZim RyanZim changed the title Typeerror with move Allow passing undefined options to move() Mar 16, 2022
RyanZim added a commit that referenced this issue Apr 9, 2022
RyanZim added a commit that referenced this issue Apr 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants