我有這樣的代碼在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.'
});
}
要重寫它的打字稿,但得到一個錯誤Property decoded does not exists on type Request
。
任何想法如何解決?
你有'Request'的類型定義嗎? –
@VadimMacagon是的,它來自'express''import {Request,Response} from「express」;' – sreginogemoh
我在[express.d.ts]中看不到'encoded'字段(https://github.com/DefinitelyTyped /DefinitelyTyped/blob/master/express/express.d.ts),它是你自己添加的字段嗎? –