Tuesday, 23 May 2017

Node.js express-jwt with express-unless gives a warning "Object is possibly 'undefined'"

Using typescript and nodejs, and express-jwt for validation of authenticity. When we use the express-jwt together with unless, as can be seen as below, tslint is complaining about the possible undefined value returned after the unless function.

import * as express from "express";
import * as jwt from "express-jwt";
import * as http from "http";

app.use("/api", jwt({ secret: refConfig.hash }).unless({ path: ["/api/auth/signin"] }));
app.set("port", 8000);
const server: http.Server = app.listen(app.get("port"), () => {
    console.log("Server is now running on port " + server.address().port);
});

The error message is as below:

[ts] Object is possibly 'undefined'.

Is it possible to get rid of this warning, and if so, what is the correct way of doing so?

Thanks in advance.



via Ali Rıza Dikici

No comments:

Post a Comment