I’ve started diving into this, and I’ve found a bunch of scenarios where I think things can be improved. Here’s a write up of the cases I have so far. I’m looking for your feedback! Please let me know what you think and how we can improve things more.
Note: Before the changes listed below, all of the examples would just say “This has type: x. Somewhere wanted: y”. I’m not going to repeat the old messages for each example, but keep the current state in mind as you read.
I’ve opted to add most things as images here. It’s a bit annoying because you can’t copy the text if you want to suggest changes, but I think it gives the best view of the results since you’ll see the applied highlighting.
General: Somewhere wanted → But it’s expected to have type
I’ve changed the phrase “Somewhere wanted:” to “But it’s expected to have type:”. All ears for feedback on even better phrasing.
Before:
1 │ /* wrong type in a list */
2 │ list{1, 2, "Hello"}->ignore
3 │
This has type: string
Somewhere wanted: int
You can convert string to int with Belt.Int.fromString.
After:
1 │ /* wrong type in a list */
2 │ list{1, 2, "Hello"}->ignore
3 │
This has type: string
But it's expected to have type: int
You can convert string to int with Belt.Int.fromString.
Math operators
This is a big one imo. That floats and ints can’t be mixed in calculations, and that floats require their own operators with a trailing dot, seems to always trip people up. I’ve spent some extra time here trying to make things clearer on what’s going on and what to do to fix it:
Adding floats
Adding ints
Using constants
Comparison operators
It’s sometimes hard to figure out why a comparison fails. I’ve tried to add more context and a short explanation anytime you use a comparison operator on something that does not have the same types.
Function arguments
In this scenario, I found it helpful to clarify that it’s the function argument that’s expected to be of another type:
Function call return mismatch
When calling a function, it’s cryptic what it is that has the type that’s wrong, and why it’s wrong. I found this phrasing to clarify things a bit:
If branch type mismatches
This one is hard to understand especially for people coming from dynamic languages - all if branches must return the same type.
If condition mismatch
Similarly to above, coming from languages with concepts like “truthy”, it can be hard to understand that in ReScript all if conditions must be bool
.
Switches
Switch branches need to return the same type. This can be difficult to spot in the current error message (as noted above by @illusionalsagacity).