I am working on a function that will return a JavaScript Object with the class instances as values and the class names as keys.
For example:
const init = (constructorMap) => {
return Object.keys(constructorMap).reduce((ret, constructorName) => {
ret[constructorName] = new (constructorMap[constructorName])();
return ret;
}, {});
};
class C1 {};
class C2 {};
const instances = init({C1: C1, C2: C2});
How can I write this in TypeScript?