5

I have express typings installed with typescript 1.8.10 and this code:

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' )
} )

which is a middleware code to catch csrf errors produces these errors:

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'.

How to prevent this ?

1 Answer 1

0

This looks like a an issue with your types, so make sure you run npm install to ensure you have all the correct dependencies.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.