加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

正则快递代码上的打字稿错误TS2345

发布时间:2020-12-14 06:07:17 所属栏目:百科 来源:网络整理
导读:我有使用typescript 1.8.10和此代码安装的快速打字: 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' )} ) 这
我有使用typescript 1.8.10和此代码安装的快速打字:

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,next: any) => any’
is not assignable to type ‘(string | RegExp)[]’. Property
‘[Symbol.iterator]’ is missing in type ‘(err: Request,
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’.

怎么预防这个?

解决方法

这看起来像是您的类型的问题,因此请确保运行npm install以确保您具有所有正确的依赖项.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读