在纯 JavaScript 中使用JSDoc
+时是否可以使用 Utility 类型,例如 Record ?tsserver
(我正在尝试创建一个设置,让我尽可能多地获得 TypeScript 的收益,而无需进行转译)
示例代码
我碰巧实际上需要一张地图,据我所知,它在 TypeScript 中被定义为“记录”:
let http = require("http");
/**@type {Record<string, Person>} */
let people = {
"1234": { name: "Bob" },
"abcd": { name: "Jane" }
};
http.createServer(function (req, res) {
res.end(JSON.stringify(people));
}).listen(process.env.PORT || 3000);
错误
但是,当我尝试使用它时,会出现此错误:
[tsserver] Cannot find name 'Record'. [E]
配置
版本:
tsc --version
:
Version 4.3.5
tsconfig.json
:
{
"compilerOptions": {
"incremental": true,
"target": "ESNEXT",
"module": "commonjs",
"lib": ["DOM"],
"allowJs": true,
"checkJs": true,
"tsBuildInfoFile": "./cache",
"noEmit": true,
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictBindCallApply": true,
"strictPropertyInitialization": true,
"noImplicitThis": true,
"alwaysStrict": true,
"noUnusedLocals": true,
"noUnusedParameters": false,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedIndexedAccess": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"moduleResolution": "node",
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
},
"include": ["**/*.js"],
"exclude": ["node_modules"]
}
作为参考,这是我设置 aletsserver
在我的.vimrc
:
let g:ale_linters = {'javascript': ['tsserver', 'jshint']}