在Typescript中,如何在函数';谁宣布的?
我想声明一个函数,将其作为处理程序传递,然后定义它,我的代码如下:在Typescript中,如何在函数';谁宣布的?,typescript,Typescript,我想声明一个函数,将其作为处理程序传递,然后定义它,我的代码如下: type authenticateHandler = (req: Restify.Request, res: Restify.Response) => any; server.post("/authentication", authenticateHandler); server.post("/v1/authentication", authenticateHandler); const authenticateHand
type authenticateHandler = (req: Restify.Request, res: Restify.Response) => any;
server.post("/authentication", authenticateHandler);
server.post("/v1/authentication", authenticateHandler);
const authenticateHandler: authenticateHandler = (req: Restify.Request, res: Restify.Response) => { ... };
我在第2行上传递函数时出现此错误,我做错了什么
TS2448:在其
声明
或者在使用常量函数之前声明它(如警告所示) 或者将其定义为一个函数:
function authenticateHandler(req: Restify.Request, res: Restify.Response) => { ... };
谢谢,我要用一个函数,因为它太长了
function authenticateHandler(req: Restify.Request, res: Restify.Response) => { ... };