Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Typescript中,如何在函数';谁宣布的?_Typescript - Fatal编程技术网

在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) => { ... };