easyHallucinated APIsNode.js
The confident method
A developer asked an AI assistant to deep-clone a settings object before mutating it inside a reducer. The suggested code runs the import fine but throws the moment the function is actually called.
settings.js
const _ = require('lodash');
function updateSettings(settings, patch) {
const draft = _.deepClone(settings);
Object.assign(draft, patch);
return draft;
}
module.exports = { updateSettings };What happens when updateSettings runs?
Object.assign throws because draft is undefined at that point.
TypeError: _.deepClone is not a function. Lodash's deep-clone method is named cloneDeep, not deepClone.
The function works correctly; there is no bug here.
The settings object clones correctly but the patch is applied in the wrong order.
Sign in with GitHub to submit an answer and track your progress.