typescript - VSCode 在 TypeScript 中不显示缺少导入
问题描述
我刚刚在一个新文件夹中创建了一个新的 TypeScript 项目。TypeScript 是 4.4.2 版。
文件夹结构如下
- myProject
-src
-folder-1
-file-1.ts
-folder-2
-file-2.ts
-tsconfig.json
包含逻辑的文件非常简单
文件 1.ts
function function_1() {
console.log('Print something');
}
文件 2.ts
function function_2() {
function_1();
}
我习惯看到的是 VSCode 在唯一的函数行中显示红色错误,function_2
因为function_1
没有导入(甚至没有导出)。
相反,VSCode 没有显示任何错误。与file-2.tsCTRL+Click
行相反,VSCode 打开file-1的实际实现。function-1()
function-1
更多,如果我运行tsc
编译器不会抱怨并在文件夹中创建相关的 * .js文件dist
。自然,如果我尝试执行function-2()
,我会收到一条错误消息,告诉我"function_1 is not defined"。
这是我的tsconfig.json
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"outDir": "dist",
"sourceMap": true,
"allowJs": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"resolveJsonModule": true
},
"include": ["src/*.ts", "src/**/*.ts"],
"exclude": ["node_modules"],
"typeRoots": ["node_modules/@types"],
"lib": ["es2016", "dom"]
}
还有一个细节。如果我运行命令npm run tsc src/folder-2/file-2.ts
(tsc
运行 TypeScript 编译器的标准 npm 脚本在哪里),我会在控制台上收到一个错误,但编译器仍然会生成file-2.js作为其输出。
我很确定我错过了一些愚蠢的东西,但我看不到它。
解决方案
推荐阅读
- c# - 包签名已启用,但未指定指纹或证书路径
- c - 在添加 openssl 库时需要帮助
- python-3.x - PostgreSQL ANSI,Python SQL,utf-8' 编解码器无法解码字节 0xa0
- intellij-idea - 如何在intellij中禁用xml突出显示?
- javascript - 来自 api 的表数据
- c# - 错误:“Program.Math()”是一种方法,在给定的上下文中无效
- perl - 使用 Mojo::DOM 提取标题后未标记的文本
- asp.net-core - 部署 .NET Core WebAPI 项目的问题
- python-3.x - 有没有办法检查 Many2one res.users 记录是否已经存在
- javascript - 如何从日志数组创建具有最新时间戳的新数组