So, I have an API that takes an options object, something like this:
type Options = { pos: number };
function doTheThing(options: Options) {
}
Now, if I call this with any of the below, I get a nice error message:
doTheThing(); // requires another argument.
doTheThing({ something: 20 }); // missing property "pos"
Great. But if I pass an empty object, Flow will consider this "unsealed" and thus have no issue with it:
doTheThing({ }); // No error, would like it to say "pos" missing instead.
So, I tried making it exact:
type Options = {| pos: number |};
Now, I get an error, but it's not very nice:
doTheThing({ }); // Cannot call `doTheThing` with object literal bound to `options` because inexact object literal [1] is incompatible with exact `Options` [2].
But I just want it to say "pos" is missing. The above is more complicated and just forces you to have to read the definition of Options in order to know what it takes. I want it to offer the actual missing property to you. Which it will do, as soon as I put any random thing in there:
doTheThing({ x: 10 }); // Cannot call `doTheThing` with object literal bound to `options` because property `pos` is missing in object literal [1] but exists in `Options`
Is there any way to get it to give me that error message on {}, instead of the less useful message? Ideally through some sort of extra annotation on the type and not some global flow configuration that like turns off unsealed objects or something.