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

237
Vistas
How to use a field in TypeScript object as a value of another field?

I am creating a const as below.

1 const result = {
2  name : input.name,
3  events : function1(input.events),
4  status : function2(events),
5 }

But at line 4, I am getting the following error.

TS2552: Cannot find name 'events'.

How can I use the events field set at line 3 as an input parameter to function2 at line 4?

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

0

You cannot refer to a field of an object literal until after you have finished creating that object.

So to use the same value twice in an object literal, you need to have a reference to that value before hand.

There are lots of ways to "have a reference" to a value, but in this case you could simply put it into a local variable first.

For example:

const events = function1(input.events)
const result = {
  name: input.name,
  events, // shorthand for `events: events`
  status: function2(events)
}
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