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

239
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
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