【发布时间】:2023-03-19 16:41:02
【问题描述】:
我讨厌问这个问题,我想这是一个非常简单的设置或打字的东西,这个新项目缺少。它将运行(通过ts-node)的事实告诉我,这只是 VS Code 的抱怨(但是,为什么?)Google 和 SO 搜索结果还没有具体。
Visual Studio 代码
版本 1.22.2
提交 3aeede733d9a3098f7b4bdc1f66b63b0f48c1ef9
日期 2018-04-12T16:38:45.278Z
壳牌 1.7.12
渲染器 58.0.3029.110
节点 7.9.0
架构 x64
> node -v
v9.10.0
> npm -v
5.6.0
> tsc -v
Version 2.8.3
> npm ls --depth=0
api-auth-test@1.0.0 C:\...
+-- @types/node@9.6.6
+-- axios@0.18.0
`-- typescript@2.8.3
> npm ls --depth=0 -g
C:\Users\...\AppData\Roaming\npm
+-- generator@1.0.1
+-- generator-gitignore@0.1.2
+-- npx@10.2.0
+-- ts-node@6.0.1
+-- tslint@5.9.1
+-- typescript@2.8.3
`-- yo@2.0.2
我发现这里在首选项、设置中提到了tsdk setting,并且我确保将 typescript 安装到本地 node_modules
"typescript.tsdk": "node_modules\\typescript\\lib\\",
编辑这个,错误会短暂消失,然后返回(我想VS刷新它的缓存。)
tsconfig.json
{
"compilerOptions": {
"target": "esnext", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"lib": [ ], /* Specify library files to be included in the compilation. */
"sourceMap": true, /* Generates corresponding '.map' file. */
"strict": true, /* Enable all strict type-checking options. */
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
}
}
package.json
{
"name": "api-auth-test",
"version": "1.0.0",
"description": "",
"main": "app.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"@types/node": "^9.6.6",
"axios": "~0.18.0",
"typescript": "^2.8.3"
},
"devDependencies": {}
}
【问题讨论】:
标签: windows typescript visual-studio-code