Let’s suppose I’m defining a module, and I have some function definitions like this:
export function bodyParser(options?:any):
(req: ExpressServerRequest, res: ExpressServerResponse, next) =>void;
export function errorHandler(opts?:any):
(req: ExpressServerRequest, res: ExpressServerResponse, next) =>void;
export function methodOverride():
(req: ExpressServerRequest, res: ExpressServerResponse, next) =>void;
export function favicon(url: string, opts? ):
(req: ExpressServerRequest, res: ExpressServerResponse, next) =>void;
export function logger(type: string, opts? ):
(req: ExpressServerRequest, res: ExpressServerResponse, next) =>void;
I’m repeatedly using this return type annotation:
(req: ExpressServerRequest, res: ExpressServerResponse, next) =>void
Is there a way to define that type, assign it a name, and just reference the name instead of repeating the same thing?
Yep! You can use an interface with a call signature:
Now you can use it like: