Looking to define an interface with function overloads and implement it?
You could start like this:
export interface ServerRouteHandler
{
( options: any, handlers: RequestHandler );
( options: any, handlers: RequestHandler[] );
( options: any, ...handlers: RequestHandler[] );
( options: any, handlers: RequestCtxHandler );
( options: any, handlers: RequestCtxHandler[] );
( options: any, ...handlers: RequestCtxHandler[] );
}
Then proceed with:
get:ServerRouteHandler = ( options: any, ...handlers: any[] ) =>
{
return this.generateRoutes('GET', options, handlers);
}
post:ServerRouteHandler = ( options: any, ...handlers: any[] ) =>
{
return this.generateRoutes('POST', options, handlers);
}
delete:ServerRouteHandler = ( options: any, ...handlers: any[] ) =>
{
return this.generateRoutes('DELETE', options, handlers);
}
This approach may seem like a workaround and can slightly alter the function's behavior.
But is there another syntax available? Maybe something like:
get<ServerRouteHandler>( options: any, ...handlers: any[] )
{
return this.generateRoutes('GET', options, handlers);
}
// Unfortunately, this does not work as expected