I'm trying to loop over an array of functions (doing network calls) that return different types of configuration objects. Based on this configuration I'm rendering react components with different props. But I'm struggling to get typescript to co-operate in this.
Here's a simplified example of what I had so far;
type FirstConfig = {
a: 'a';
};
type SecondConfig = {
b: 'b';
};
type ConfigObject = FirstConfig | SecondConfig;
type ConfigFunction = () => ConfigObject;
const configArray: ConfigFunction[] = [() => ({ a: 'a' }), () => ({ b: 'b' })];
configArray.map(getConfig => {
const { a, b } = getConfig();
console.log(a, b);
});
Whenever I loop over the array of config functions and call it, It seems to complain that none of the properties defined on the ConfigObject are present. Any tips/guidance here?
