sodiray / radash

Functional utility library - modern, simple, typed, powerful
https://radash-docs.vercel.app
MIT License
4.1k stars 160 forks source link

`assign` does not handle `null` values well #373

Open anion155 opened 8 months ago

anion155 commented 8 months ago
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} }

MoozonWei commented 3 months ago

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.

aleclarson commented 1 month ago

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.