Skip to content

{..} usage allows weird type-checks #6267

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
ryyppy opened this issue May 26, 2023 · 2 comments
Closed

{..} usage allows weird type-checks #6267

ryyppy opened this issue May 26, 2023 · 2 comments
Labels
stale Old issues that went stale

Comments

@ryyppy
Copy link
Member

ryyppy commented May 26, 2023

I tried to explain {..} to another user and while typing out some examples I created a code snippet that actually compiled (even though I think shouldn't):

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

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

someObj["name"] = 1

let myFn = (obj: {"name": string, "twitter": string}) => {
  Js.log(obj)
}

myFn(someObj)

IMO either it should have yielded a type error on the second name assignment, or at least error out in the myFn(someObj) call, since I'd expect someObj["name"] to be of type int.

Is this intentional?

@CarlOlson
Copy link

CarlOlson commented May 26, 2023

I think this is intentional. {..} is a concrete type, right? So assigning a property to it doesn't refine it (compared to Typescript for example). I've used this to quickly port JS code to non-idiomatic ReScript.

However, this will still compile:

@val external someObj: {.. "name": string} = "someObj"
someObj["name"] = 1

I feel like that should be an error. The compiler is treating getters and setters separately. Maybe that is useful to someone? 🤷

Copy link

github-actions bot commented Sep 5, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale Old issues that went stale label Sep 5, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Sep 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Old issues that went stale
Projects
None yet
Development

No branches or pull requests

2 participants