I am currently in the process of converting a JavaScript library to TypeScript and need to define proxy functions. These functions should be able to accept any type and number of parameters and pass them to the original function like so:
async function any(table: string, columns?: string[], conditions?: object): Promise<object[]>
async function any(table: string, conditions?: object): Promise<object[]>
async function any(queryFunction: object): Promise<object[]>
async function any(...params: any[]): Promise<object[]> {
return Promise.resolve([])
}
async function one(table: string, columns?: string[], conditions?: object): Promise<object>
async function one(table: string, conditions?: object): Promise<object>
async function one(queryFunction: object): Promise<object>
async function one(...params: any[]): Promise<object> {
return (await any(...params))[0]
}
However, when I try to compile using tsc
, I get the error
A spread argument must either have a tuple type or be passed to a rest parameter.
.
The solutions I have come across for this issue do not quite fit my specific use case. I do not want to deal with all possible parameter variations within the body of the proxy function, as it would create significant overhead. I also do not want to use a ...param: any[]
overloading definition in the first function, as I want the parameter variations to be strict.
Does anyone have a good idea on how to effectively solve this issue?
Thank you and best regards.