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 the "{..}" construct to syntax lookup #652

Open
alarbada opened this issue Feb 24, 2023 · 5 comments
Open

Add the "{..}" construct to syntax lookup #652

alarbada opened this issue Feb 24, 2023 · 5 comments

Comments

@alarbada
Copy link

I have no idea what that actually does, I found it in some declaration files.

@ryyppy
Copy link
Member

ryyppy commented May 26, 2023

That is an open object type. They are mostly relevant for external usage where you'd receive a object of "any structure" and you'd then use it the way you think it should be used.

Example:

@val external someObj: {..} = "someObj"

someObj["name"] = "Patrick"
someObj["twitter"] = "@ryyppy"

Playground Link

@alarbada
Copy link
Author

alarbada commented May 26, 2023

Mmm, so like an object map, kind of a { [ key: string]: any } in typescript?

Shouldn't then this be on the syntax lookup?

Edit: I mean, these quirks are really difficult to search. I am partly not using rescript because of that (also I don't believe I'm the target audience).

@ryyppy
Copy link
Member

ryyppy commented May 26, 2023

There's a few more subtle things to consider when using this type. (had to create a new issue to clarify some things here).

It should be on the syntax lookup and most likely in the object / interop sections at some point.

@CarlOlson
Copy link

Edit: I mean, these quirks are really difficult to search. I am partly not using rescript because of that (also I don't believe I'm the target audience).

If it helps. This is used very rarely, it has legitimate uses, but is generally an escape hatch.

The { [ key: string]: any } type is closer to Js.Dict.t<any>, only there is no any type in ReScript. Js.Json.t is often used for any unknown data.

@ivan-demchenko
Copy link

ivan-demchenko commented Dec 1, 2023

Hi @ryyppy and @CarlOlson,
Actually, this escape hatch is used in a very important place (where it shouldn't be). I started a thread here and an issue here.
TL;DR:

<input
  onChange={evt => {
    let x = ReactEvent.Form.target(evt)["value"] // x is 'a
    setIntegerValue(_ => x) // x is int, should not happen!
  }}
/>

I agree with @alarbada, this looks like something that shouldn't even take place in a language like Rescript.

@ryyppy I think in my example the compiler should panic if there's no decoder in place because evt.target.value can be anything and will blow up at runtime. Would you agree that a decoder should be used here?

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

4 participants