Repository navigation
Conversation
docs for assignMany but no examples.
test updates
glennsl
left a comment
There was a problem hiding this comment.
In addition to the comments below, and as pointed out in the previous PRs, all the get and set functions are unsafe. It might be outside the scope of this PR to rename them to add the Unsafe suffix, but I think the docstrings should still clearly say that they're unsafe, and explain why.
|
|
||
| See [Object.assign on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign) or [ECMAScript Language Specification](https://tc39.es/ecma262/multipage/fundamental-objects.html#sec-object.assign). | ||
| */ | ||
| external assignMany: ({..}, array<{..}>) => {..} = "Object.assign" |
There was a problem hiding this comment.
Same here. And with the potential functions assign2, assign3 and such of course.
There was a problem hiding this comment.
I recommend removing it and not introducing assign2, assign3, etc. As you noted other places the developer can chain calls to assign and get the same result. But I'll do what you recommend. What should I do?
There was a problem hiding this comment.
You shouldn't do what I recommend, but I agree :)
There was a problem hiding this comment.
I don't understand. Who decides this? We both agree to remove it. @zth need your input here.
There was a problem hiding this comment.
Who actually makes the decisions, and how, is just one of many mysteries around ReScript that you'll have to accept. The project has a history of poor management, though it's getting better! But still quite mysterious, unfortunately.
But for this library I suppose it's ultimately whoever has commit access, which is definitely @zth, and I'm sure @cknitt as well.
|
Could you explain why they are unsafe? The getters will fail if given null and undefined. Anything else? When will setters fail? |
|
Hmm. Actually I don't think you can call this with a null or undefined object. So I don't know when the getters fail. |
Sure, sorry. If it was that obvious these probably wouldn't exist in this form anyway. Here are examples where let obj = {"foo": 42}
let x: int = obj["foo"]
// let x: string = obj["foo"] // Error: This has type: int, Somewhere wanted: string
let x: option<string> = get(obj, "foo") // Should error, as above, because it's actually an int
// obj["foo"] = "bar" // Error: This has type: string, Somewhere wanted: int
set(obj, "foo", "bar") // Should error, as above, because it's actually an int
// let x: string = obj["foo"] // Error: This has type: int, Somewhere wanted: string
let x: int = obj["foo"] // Just to show that the type is still int, despite now containing a string |
|
In several places I have suggested the getter return type I agree the setter is a problem when setting a property on an object ReScript thinks it knows the type of. Hadn't thought of that. Do you really think this warrants the |
|
I attempted to write the docs for |
It also removes the convenience and reason for these existing. These functions should probably just be removed.
As I've said elsewhere, I think everything unsound should be marked as |
If the functions are removed then I wasted a lot of time on this. I just started documenting the ArrayBuffer stuff and that is dangerous too. If it is a waste of time I want to know now. I think we should provide safe alternatives wherever we can and there are none in the Object module. I thought it was safe when I saw the The other place where I care about this is Error.t. I still can't get the "code" property out of a custom exception. I'd like to see a safe getter there. Need some decisions here. At a minimum I like the idea of beefing up the I'm going to wait for @zth before marking everything as |
|
You're forgetting that the language has built-in syntax for object access too: let x: string = obj["code"]And this is entirely safe for well-defined object types.
This isn't going to help you with that though. But I like the idea of having these kinds of accessors in the |
|
I'm not forgetting anything. I'm fully aware this Object module is a kludge for weird interop scenarios. That's why my docs include language like "ReScript provides type-safe compile-time support for JavaScript objects that may be more convenient/safe. See ..." |
|
Reviewing and looking to merge this soon. Could this be rebased perhaps? |
I'm not sure I did what you wanted but I merged all the object doc strings I did into this PR. It was a hassle getting them all merged. So I think if you accept this then all the others can be closed.