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

Add array notation for path type #979

Open
NicolasCwy opened this issue Nov 8, 2024 · 3 comments
Open

Add array notation for path type #979

NicolasCwy opened this issue Nov 8, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@NicolasCwy
Copy link

NicolasCwy commented Nov 8, 2024

Would it be possible to add an option to make paths in array format instead of dot format
Some form item libraries e.g Antd use arrays of strings/ number to denote the path, essentially splitting them by the "." that separates them.

type Obj = {
  a: {
    b: {
      e: string;
    };
    c: {
      d: ['foo'];
    };
  };
};

// Current feature
a.c.d[0]
a.c.d.0

// New Feature - array notation
["a", "c", "d", 0] 

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • The funding will be given to active contributors.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar
@NicolasCwy NicolasCwy added the enhancement New feature or request label Nov 8, 2024
@NicolasCwy NicolasCwy changed the title Add option to ignore arrays in Path type Add option to make path an array type instead of dot notation Nov 9, 2024
@NicolasCwy NicolasCwy changed the title Add option to make path an array type instead of dot notation Add array notation for path type Nov 9, 2024
@NicolasCwy
Copy link
Author

NicolasCwy commented Nov 12, 2024

Seems like what is needed is in the Get source file, with some slight tweaks

// Current behaviour
ToPath<'foo[0].bar.baz'>
//=> ['foo', '0', 'bar', 'baz']

// Expected behaviour
ToPath<'foo[0].bar.baz'>
//=> ['foo', 0, 'bar', 'baz'] // 0 should be a number since it is an array index

@fregante
Copy link
Collaborator

fregante commented Nov 12, 2024

Seems like what is needed is in the Get

Can this whole request be summarized into: Use number for array indexes in ToPath?

@NicolasCwy
Copy link
Author

NicolasCwy commented Nov 12, 2024

Yes and also ToPath has to be exported as well. Let me change the title and description

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

No branches or pull requests

2 participants