Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

203
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda