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

path/prop: also allow number (esp. for navigating arrays)? #94

Closed
KiaraGrouwstra opened this issue Sep 11, 2016 · 2 comments
Closed

path/prop: also allow number (esp. for navigating arrays)? #94

KiaraGrouwstra opened this issue Sep 11, 2016 · 2 comments

Comments

@KiaraGrouwstra
Copy link
Member

Currently, Ramda's path / prop and similar methods are described in their docs as using string paths/props, while in its implementation -- and imho reasonably so esp. when dealing with Arrays -- also allows numbers:

R.path([0, 'a'], [{ a: 1 }])
// 1
R.path(['0', 'a'], [{ a: 1 }])
// 1
R.prop(0, ['a'])
// "a"
R.prop(0, { '0': 'a' })
// "a"

Now, I would like for the typings to also allow me to use these functions how I was already using them. You may counter this would clash with Ramda's docs, and therefore possibly intention. So I guess the question here is, would you consider this a bug in Ramda's implementation, or should we request they adjust their docs and accordingly allow this in the typings?

@KiaraGrouwstra
Copy link
Member Author

Note that toPairs does use {[k: string]: S} | {[k: number]: S}. I'm thinking we could have a type Prop = string | number;, a type Path = Prop[];, then have toPairs use {[k: Prop]: S} to abstract that part.

@jcristovao
Copy link
Collaborator

I would say that it's probably Ramda's docs which are outdated, but perhaps you should ask there ;)

Nevertheless, a PR is most welcomed, you seem to be heading in the right direction

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

No branches or pull requests

2 participants