Skip to content
This repository has been archived by the owner on Jan 23, 2021. It is now read-only.

Deep assigning objects with different property types #15

Closed
parro-it opened this issue Jan 30, 2016 · 1 comment
Closed

Deep assigning objects with different property types #15

parro-it opened this issue Jan 30, 2016 · 1 comment

Comments

@parro-it
Copy link

I have to assign an object to another that could have prop of different kind.

In this example:

var assign = require('deep-assign');
assign({ prop: 'test1' }, { prop: ['u'] });

deep-assign try to set string characters to elements of the ['u'] array, and it throws
TypeError: Cannot assign to read only property '0' of [object String].
You can test it on tonicdev

I was instead expecting to obtain as result { prop: ['u'] }. That is, I was expecting the whole target prop to be overwritten by the source prop, being it a string and not an object.

Is this by design? If not , I could write a PR to implement the expectation I explain.

@schnittstabil
Copy link
Contributor

@parro-it In my opinion that is the expected behavior, because we recursively Object.assign():

assign({ prop: 'test1' }, { prop: ['u'] });

// should be similar to
{prop: deep_assign('test1', ['u'])}

// which have to be the same as 
{prop: Object.assign('test1', ['u'])}
//=> TypeError: Cannot assign to read only property '0' of [object String]

I'm open for suggestions, but please read #13 (comment) first.

I close this issue, in favor of #13, please reopen if needed.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants