2016-11-15 117 views
4

我有打字稿1.8.10安装快递分型和验证码:打字稿错误TS2345

app.use(function(err, req, res, next) { 
    if (err.code !== 'EBADCSRFTOKEN') { 
     return next(err) 
    } 

    // handle CSRF token errors here 
    res.status(403) 
    res.send('form tampered with') 
}) 

这是一个中间件代码来捕获CSRF错误产生这些错误:

Error:(130, 10) TS2345: Argument of type '(err: Request, req: Response, res: NextFunction, next: any) => any' is not assignable to parameter of type 'string | RegExp | (string | RegExp)[]'. Type '(err: Request, req: Response, res: NextFunction, next: any) => any' is not assignable to type '(string | RegExp)[]'. Property '[Symbol.iterator]' is missing in type '(err: Request, req: Response, res: NextFunction, next: any) => any'.

Error:(131, 14) TS2339: Property 'code' does not exist on type 'Request'.

Error:(136, 9) TS2339: Property 'status' does not exist on type 'NextFunction'.

Error:(137, 9) TS2339: Property 'send' does not exist on type 'NextFunction'.

如何防止这种情况?

回答

0

这看起来像是一个类型问题,因此请确保您运行npm install以确保您拥有所有正确的依赖关系。