我在一个 JavaScript 项目中使用tsserver
了 with JSDoc
in 。vim
我遇到了以下问题:
/** @type {import('express').Handler} */
function requireUser(req, res, next) {
if (!req.user) {
throw new Error("Unauthorized");
}
next();
}
这是错误:
[tsserver] Property 'user' does not exist on type 'Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>'. [E]
当然,我的代码中有数百个地方req.user
被引用。
这是我当前的tsconfig.json
,供参考:
{
"compilerOptions": {
"target": "es2021",
"module": "commonjs",
"allowJs": true,
"checkJs": true,
"noEmit": true,
"strict": true,
"alwaysStrict": true,
"noUnusedLocals": true,
"typeRoots": ["./@types", "./node_modules/@types"],
"esModuleInterop": true,
"preserveSymlinks": false,
"maxNodeModuleJsDepth": 20,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
},
"include": ["src/**/*.js"],
"exclude": ["node_modules"]
}
我已经尝试将一个包含./@types/types.d.ts
整个文件的文件放入namespace Express
Typescript 声明合并,但它似乎没有生效。