TypeScript Express Error Function

后端 未结 3 1411
星月不相逢
星月不相逢 2021-01-18 10:27

What are the types of the four parameters for the error handling function when coding in Typescript?

app.use((err: ??, req: ??, res: ??, next: ??) => { }         


        
3条回答
  •  旧巷少年郎
    2021-01-18 10:59

    I don't know why Typescript does not get that we are passing an error handler.

    These are the solutions I found possible :

    app.use((err, req, res, next) => {}) // KO    
    
    const inVariable : ErrorRequestHandler = (err, req, res, next) => {};
    
    app.use(inVariable); // ok
    app.use(((err, req, res, next) => {}) as ErrorRequestHandler); // ok
    

提交回复
热议问题