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

549
Visualizações
Why Object.entries not taking correct types from an object type defined with "Record<>"

Why the type of object key is not properly picked by typescript?

const k: Record<'a' | 'b', number> = { a: 5, b: 6 };

Object.entries(k).forEach(([key, value]) => {
  // key: string
  // value: number
});

I was expecting the types to be

key: 'a' | 'b'
value: number

Because we are saying Record<'a' | 'b', number> and not Record<string, number>.

Also how can I fix this in a safe way with out using any?

playground

There is a possible duplicate here. But that question is not following the minimal-reproducible-example - and hence the answers are too. I felt like that thread is taking too much energy to understand because it is not generalized.

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