I am trying to create a function that iterates through a list of ioredis clients and write the data provided to all of them, at the moment, the function implementation looks like this:
public writeAll(args: any) {
return this.clients.map((client) => client.set.apply(this, args));
}
But as you can already see, the implementation has two problems:
Is it possible to copy the argument types of ioredis to this function and also not get the arguments as an array?
Use rest parameters and the built-in Parameters
type:
public writeAll(...args: Parameters<Redis["set"]>) {
return this.clients.map((client) => client.set.apply(this, args));
}