Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deepStringAssign created and tested, closes #7 #8

Merged
merged 6 commits into from
Oct 12, 2023
Merged

Conversation

fidel-ml
Copy link
Contributor

@fidel-ml fidel-ml commented Feb 9, 2023

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 like Partial, 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.

@fidel-ml fidel-ml added the enhancement New feature or request label Feb 9, 2023
@fidel-ml fidel-ml self-assigned this Feb 9, 2023
@fidel-ml fidel-ml linked an issue Feb 9, 2023 that may be closed by this pull request
@fidel-ml fidel-ml changed the title deepStringAssign created and tested, closes #6 deepStringAssign created and tested, closes #7 Feb 9, 2023
@alanrodas
Copy link
Member

Docs must be regenerated in order to merge. This issue will be presented over and over when multiple pull-requests are performed, and thus, maybe we need a different way of serving the docs.

@alanrodas alanrodas merged commit d2a3fe7 into main Oct 12, 2023
2 checks passed
@alanrodas alanrodas deleted the 7-new-deep-assign branch October 20, 2023 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create a function for deep assign of string typed keys.
2 participants