deepStringAssign created and tested, closes #7 #8
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The function
deepStringAssign
was created.It uses the Utility Type
Subset
, that was also created, following a post in a blog (see documentation).Subset
is likePartial
, but it works on any level of the object, not just the first.It is needed by
deepStringAssign
so the elements used as sources for the changes may be incomplete on any level.The function is parametric, so the type of the target is preserved.
The sources of changes contains subsets of the keys of the target object, and only those are overwritten (if their values have type string).
Different from the
Object.assign
function,deepStringAssign
works by cloning the target object, and rewriting the corresponding keys with the values from the sources. This work is needed for the function to be used on existing constants without altering them.The function
Object.assign
can be used on an empty object, and all options can be assigned, but in that way, the type of the original object is lost (objects with any combination of keys may be created).The function
deepStringAssign
uses a copy of the target object, so all its keys are preserved, and only those can be overwritten.