I have a scenario where I have two objects defined as one
and two
, each containing props. These objects are then stored in an array called packages
.
const one = {
props: {
num: 2
}
}
const two ={
props: {
name: 'j'
}
}
const packages = [one, two]
Now, I want to create a new variable that combines the props of all the items in the packages
array into a single object.
Type CombineProps = {
num: number
name: string
}
I attempted to achieve this using the reduce
function on the packages
array, but encountered issues while working with TypeScript.
const props = package.reduce(previous, item => {...previous, ...item.props},{})
Can anyone suggest a solution to resolve this? Thank you.