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

WIP: Typescript definitions #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

WIP: Typescript definitions #7

wants to merge 2 commits into from

Conversation

bambeusz
Copy link

set function needs improvement. I'm not even sure it is possible to make it in typescript definition files.

Problem:
The path parameter might be a string, which contains of keys, separated with dot. We'd need to define n-level nesting (Where n = numberOfDots + 1) in ImmutableSetReturnFromPathString type somehow. Perhaps it would be a good idea to implement this method in typescript itself, and - if needed - slightly modify it, in order for it to be more "typed-way". wdyt?

Another story is: what if a user wants (for GodKnowsWhy reason), to have resulting object with key, that contains a dot e.g.

{
  foo: {
    bar: {
      'baz.zar': 'a value',
    }
  }
}

Is there a way to do that using set method?

Copy link
Owner

@Lukasz-pluszczewski Lukasz-pluszczewski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding your questions:

  1. number of elements (levels) in path may not be necessarily be equal to numberOfDots + 1, as array-like syntax is supported:
    foo.bar[1][2][baz].lorem[ipsum]
    You could just (if it's even possible) implement src/stringToPath.js function in typescript. It returns an array of strings or numbers (in case of numeric array-like path elements). The length of that array is n value you are looking for
  2. if there is a field with dot in nested structure it is not going to work correctly (set would create new field). I am not able to differentiate those two situations:
foo : {
  'bar.baz': 'value',
}
foo: {
  bar: {
    baz: 'value',
  },
}

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

Successfully merging this pull request may close these issues.

2 participants