I have this code in javascript:
if (token) {
    // verifies secret and checks exp
    jwt.verify(token, Config.Secret, function(err, decoded) {      
      if (err) {
        return res.json({ success: false, message: 'Failed to authenticate token.' });    
      } else {
        // if everything is good, save to request for use in other routes
        req.decoded = decoded;    
        next();
      }
    });
  } else {
    // if there is no token
    // return an error
    return res.status(403).send({ 
        success: false, 
        message: 'No token provided.' 
    });
  }
Want to rewrite it to typescript but getting an error Property decoded does not exists on type Request.
Any ideas how to solve that?
If you don't want to make a new class extending Request you may access request as an object like:
req['decoded'] = decoded;
If it stills throws at you you may have to cast req as an object (typescript):
(<Object>req)['decoded'] = decoded;
You may even cast req to type any and access decoded as property (typescript):
(<any>req).decoded = decoded;
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With