radash icon indicating copy to clipboard operation
radash copied to clipboard

`assign` does not handle `null` values well

Open anion155 opened this issue 1 year ago • 2 comments

const r = require('radash')
const result = r.assign({ a: {g:5} }, { a: null })
console.log(result)

Expected result would be { a: null }, but it is { a: {g:5} }

anion155 avatar Dec 22 '23 16:12 anion155

I think this issue is caused by this line: https://github.com/sodiray/radash/blob/069b26cdd7d62e6ac16a0ad3baa1c9abcca420bc/src/object.ts#L276

Although this assign function is designed to merge two objects, you will still encounter situations where you need to merge non-objects and objects when it make recursive calls.

Maybe we can modify this function to be able to merge objects and non-objects, then the problem will be solved.

moo-w avatar May 10 '24 06:05 moo-w

Hi @anion155 and @MoozonWei, I have this fixed over at the Radashi fork: https://github.com/radashi-org/radashi/pull/112

You can use it today by installing radashi@beta (see changelog here). An official release is pending. If you have any more ideas or feedback, consider sharing it here.

aleclarson avatar Jul 16 '24 14:07 aleclarson