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

Create a function for deep assign of string typed keys. #7

Closed
fidel-ml opened this issue Feb 9, 2023 · 0 comments · Fixed by #8
Closed

Create a function for deep assign of string typed keys. #7

fidel-ml opened this issue Feb 9, 2023 · 0 comments · Fixed by #8
Assignees
Labels
enhancement New feature or request

Comments

@fidel-ml
Copy link
Contributor

fidel-ml commented Feb 9, 2023

The function Object.assign works on a shallow level, assigning only strings on the first level.
When nested objects are used, a similar functionality but working on any depth level may be handy.

For example:

   interface A {
       a1: string;
       a2: {
           a21: string;
           a22: string;
       };
   }
   const defaultA: A = { a1: 'Default A1', a2: { a21: 'Default A21', a22: 'Default A22' } };
   const ej1: A = deepStringAssign<A>(defaultA, { a2: { a21: 'User A21' } });
   // EXPECTED: ej1 === { a1: 'Default A1', a2: { a21: 'User A21', a22: 'Default A22' } };
   const ej2: A = deepStringAssign<A>(defaultA, { a1: 'User A1' },
                                                { a2: { a22: 'User A22' } });
   // EXPECTED: ej2 === { a1: 'User A1', a2: { a21: 'Default A21', a22: 'User A22' } };
@fidel-ml fidel-ml self-assigned this Feb 9, 2023
@fidel-ml fidel-ml added the enhancement New feature or request label Feb 9, 2023
@fidel-ml fidel-ml linked a pull request Feb 9, 2023 that will close this issue
alanrodas added a commit that referenced this issue Oct 12, 2023
deepStringAssign created and tested, closes #7
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 a pull request may close this issue.

1 participant