I'm currently in the process of converting some react native code to typescript, and I've encountered issues with certain reduce functions. How can I refactor this code to avoid type errors during execution?
I have experimented with different approaches to typing both the function and its expected output, but haven't been successful yet.
myArray: data.items.reduce( (map: object, obj: myInterface) : object => { map[obj.id] = obj; return map; }, [])
The 'myArray' property of my object should be filled with an array of items defined in 'myInterface'. However, when I try to run the code, I encounter the following error:
TypeScript error in MyPath/:
Element implicitly has an 'any' type because expression of type 'number' can't be used to index type '{}'.
No index signature with a parameter of type 'number' was found on type '{}'. TS7053
128 | appVersion: data.version || "",
129 | offline: false,
130 | myArray: data.items.reduce( (map: object, obj: myInterface) : object => { map[obj.id] = obj; return map; }, [])
| ^
131 | });