【发布时间】:2020-09-17 13:21:11
【问题描述】:
我有以下代码
app.use(function (req: Request, res, next) {
req.version = req.headers['accept-version'] || '1.0.0';
next();
});
我有文件 express.d.ts
declare namespace Express {
export interface Request {
version?: string | string[];
}
}
并在 tsconfig.json
"compilerOptions": {
// other options
"typeRoots": ["./typings", "./node_modules/@types"]
},
"include": [
"src/**/*.ts",
"typings/**/*"
],
此设置已解决问题
类型“Request
”上不存在属性“version”。
在 vscode 本身中。但是,在执行npm run start 或nodemon 时,终端中会出现问题。
我错过了什么吗?
【问题讨论】:
-
我有同样的错误 - 在 vscode 中似乎没问题
标签: node.js typescript express