Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

133
Vistas
Defining TypeScript function taking object with unspecified number of keys

I have a function that takes an object as an input and returns an object as well. I would like to define it such that it can have any number of keys in the input or returned object.

Right now, I define it like this:

const myFunc: ({}) => ({})

Is there a good way to write it to avoid any type errors while also using the advantages that TS provides?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can use TypeScript's Record<K, V> type to specify an object with arbitrary keys of type K and values of type V:

type MyObj = Record<string, any>;

Keys must be strings, numbers, or symbols, but values can be any type you specify. Your function would then become:

const myFunc = (obj: Record<???, ???>): Record<???, ???> => { /* ... */ };
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda