Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Calculadora

0

62
Vistas
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.

7 months ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar empleo Planes Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2023 PeakU Inc. All Rights Reserved.