Given the following code:
function SumSystem() {
return {
sum(x: number, y: number) {
return x + y
}
}
}
function MultiplySystem() {
return {
multiply(x: number, y: number) {
return x * y
}
}
}
function emit<S extends () => Record<string, unknown>>(systems: S[]): { [K in keyof ReturnType<S>]: ReturnType<S>[K] } {
// whatever
return {}
}
emit([SumSystem]).sum(1, 2) // works
emit([MultiplySystem]).multiply(2, 2) // works
emit([SumSystem, MultiplySystem]).sum(1, 2) // does not work
emit([SumSystem, MultiplySystem]).multiply(2, 2) // does not work
As per comments, the last two emits are not working, and that's occurring because I am passing two values into the argument's array: [SumSystem, MultiplySystem].
Questions:
- What's the problem?
- Is it possible to fix it?
- If the second question is true, how?