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

Record.keys/entries/values #338

Open
bakkot opened this issue Jul 25, 2022 · 4 comments
Open

Record.keys/entries/values #338

bakkot opened this issue Jul 25, 2022 · 4 comments

Comments

@bakkot
Copy link
Contributor

bakkot commented Jul 25, 2022

I just noticed that the Record constructor does not have a way of getting the keys out of a Record. In fact, as far as I can tell, there is no such facility anywhere in this proposal.

An earlier version had a Record.keys method which was like Object.keys except it returned tuples. I agree that such a thing need not exist in V1 of this proposal. But I was actually expecting Record.keys to be like Object.keys except that it accepted Records. Was that discussed and rejected? If it was, is there an alternative way of getting the keys from a Record (short of a for-in loop)? It seems like there ought to be such a thing, and it seems like the obvious place to put it would be Record.keys.

Ditto, of course, for values and entries.

@acutmore
Copy link
Collaborator

acutmore commented Jul 25, 2022

Earlier discussion here: #133

Closed as "not part of V1". Object.keys will work with records, in the same way that it works on strings.

@bakkot
Copy link
Contributor Author

bakkot commented Jul 25, 2022

#133 is talking about a different feature than what I am discussing here; see my second paragraph.

I would find it pretty strange to pass a Record to a method on the Object constructor, but I guess it's better than such a facility not existing at all. (I also find it very strange to pass a string to the Object constructor; I've never done that and would look askance at any code which did.)

@acutmore
Copy link
Collaborator

(I also find it very strange to pass a string to the Object constructor; I've never done that and would look askance at any code which did.)

I agree, I only meant to demonstrate that Object.keys already works with primitives so without changing anything it already works for records. The part I would find strange about passing a string is not that it’s a primitive and more that it’s a list, I would also find it odd to pass an array to Object.keys. To me, Records being bags of string properties makes it feels more natural to ask for it’s object’s keys.

@ljharb
Copy link
Member

ljharb commented Jul 26, 2022

I do think it’d be perfectly fine to add keys/values/entries/fromEntries to Record, fwiw, I’m just not sure the use case is compelling enough. (also probably hasOwn for consistency even tho it can’t have any inherited properties)

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

No branches or pull requests

3 participants