Answer the question
In order to leave comments, you need to log in
How to correctly create a method overload?
An external library type declaration is given. I quote the used parts from it:
interface IRouterMatcher<T> {
(path: PathParams, ...handlers: RequestHandler[]): T;
(path: PathParams, ...handlers: RequestHandlerParams[]): T;
}
interface IRouterHandler<T> {
(...handlers: RequestHandler[]): T;
(...handlers: RequestHandlerParams[]): T;
}
interface IRouter extends RequestHandler {
// ...
use: IRouterHandler<this> & IRouterMatcher<this>;
// ...
}
export default class Router extends RequestHandler {
// ...
use(path: PathParams, ...handlers: RequestHandler[]): this
use(path: PathParams, ...handlers: RequestHandlerParams[]): this
use(...handlers: RequestHandler[]): this
use(...handlers: RequestHandlerParams[]): this {
// ...
return this;
}
// ...
}
error TS2394: Overload signature is not compatible with function implementation.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question