// Within tsconfig.json under "compilerOptions"
"typeRoots": ["./@types", "./node_modules/@types"],
// Define custom types for Express Request in {projectRoot}/@types/express/index.d.ts
declare global {
namespace Express {
interface Request {
verifiedAccessToken: string
}
}
}
Even after annotating req as Express Request in a different file's function parameter, setting verifiedAccessToken causes a linting error in VsCode:
req.verifiedAccessToken = accessToken;
// Property 'verifiedAccessToken' does not exist on
// type 'Request<ParamsDictionary, any, any, ParsedQs>'.ts(2339)
Any additional steps required to use the declaration file?
// Check package.json for relevant dependencies
"dependencies": {
"express": "^4.17.1",
"node-typescript": "^0.1.3",
"ts-node": "^9.0.0",
"typescript": "^3.9.7"
},
"devDependencies": {
"@types/express": "^4.17.8",
"@types/node": "^14.0.27",