interface IPlugin1 {
method1(): void;
event1: (callback: () => void) => void;
}
interface IPlugin2 {
method2(): number;
event2: (callback: (result: number) => void) => void;
}
type CombinedPlugin = IPlugin1 & IPlugin2;
function combinePlugins(plugins: CombinedPlugin[]): { [key: string]: any } {
const results: { [key: string]: any } = {};
plugins.forEach((plugin, index) => {
try {
if ('method1' in plugin) {
plugin.method1();
results[`plugin${index + 1}_method1`] = 'Successfully called method1';
}
if ('method2' in plugin) {
const method2Result = plugin.method2();
results[`plugin${index + 1}_method2`] = method2Result;
}
if ('event1' in plugin) {
plugin.event1(() => {
results[`plugin${index + 1}_event1`] = 'Event1 callback executed';
});
}
if ('event2' in plugin) {
plugin.event2((result) => {
results[`plugin${index + 1}_event2`] = `Event2 callback executed with result: ${result}`;
});
}
} catch (error) {
results[`plugin${index + 1}_error`] = `Error in plugin ${index + 1}: ${error.message}`;
}
});
return results;
}