Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

110
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!