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

111
Visualizações
Typing the reduce method

I am trying to add typing to the reduce method. So I'm looking at something like this:

interface tmp {
  foo: string;
  bar: string;
}

const a: tmp = {
  bar: 'value',
  foo: 'value2',
}

const b: tmp = Object.keys(a).reduce((acc,key: string) => {
  acc[key] = key;
  return acc;
}, {})

The problem is, I'm getting this error:

Type '{}' is missing the following properties from type 'tmp': foo, bar

Which is true, but not really. How can I make this setup work?

I tried doing this:

type keysType = { [key in keyof typeof ParameterLabels]: string }; export const ParameterNames: ParameterInputs = Object.keys(ParameterLabels).reduce( (acc, key) => { acc[key] = key; return acc; }, {}, );

But now I'm getting this error:

Argument of type '{}' is not assignable to parameter of type 'keysType'. Type '{}' is missing the following properties from type 'keysType': parameterType, type, name, minValue, and 6 more.

on passing of the accumulator.

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