rescript-compiler
rescript-compiler copied to clipboard
Improve "is not a subtype of" error messages
A lot of the recent features in rescript make use of subtyping in various ways. But, the error messages around subtyping aren't great, they mostly just say that x is not a subtype of y, but not why. We should improve those.
And the last example in the ‘Record Type Coercion’ section seems not to work.
type a = {
name: string,
// mandatory, but explicitly typed as option<int>
age: option<int>,
}
type b = {
name: string,
// optional field
age?: int,
}
let nameFromB = (b: b) => b.name
let a: a = {
name: "Name",
age: Some(35),
}
let name = nameFromB(a :> b)
Error message is just Type a is not a subtype of b.
I noticed some cases where the message doesn't even show up in V11 (the compiler exits with a Not_found exception) (#6571)