Skip to content

Allow records in js objects #4922

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

Closed
bobzhang opened this issue Jan 27, 2021 · 1 comment
Closed

Allow records in js objects #4922

bobzhang opened this issue Jan 27, 2021 · 1 comment

Comments

@bobzhang
Copy link
Member

type t = {
  y : int
}
let x = {"x" : { y : 3}}

let u : t = x["x"]

Here the nested record is still interpreted as structural type.
It used to work this way for two reasons:

  • record was compiled as an array
  • the ocaml syntax is quite heavy for nested structual objects, so I chose to inherit, otherwise it would be as below which is too verbose
[%obj{x = [%obj{y = 3}]]

To fix this, the work may be done on my side (the internal ppx), for rescript syntax, the structural objects will not be inherited.
This would be a breaking change for rescript syntax (in a good way).

Note this is not an issue in type space, since object types have different syntax < x : int> vs {x:int}
Question: does it make sense to change the semantics of ocaml syntax as well, not inherit the structual property inside the nested objects?

@jfrolich
Copy link
Contributor

This would be very welcome. I do think explicit non-nesting behavior is better in every case.

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