jprichardson / node-fs-extra

Node.js: extra methods for the fs object like copy(), remove(), mkdirs()
MIT License
9.44k stars 776 forks source link

Allow passing undefined options to move() #947

Closed Nokel81 closed 2 years ago

Nokel81 commented 2 years ago

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 commented 2 years ago

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.

Nokel81 commented 2 years ago

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 commented 2 years ago

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