Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

208
Views
How to get "property missing" error messages with empty (and thus unsealed) objects

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.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!