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.