angularjs – 在VS Code中找不到“无法找到名称’x’”的Typescript错误

我的应用程序编译(转换)就好了,但Visual Studio代码仍然显示很多错误

在某些情况下(例如角度和离子),问题是通过包含Angular / Ionic而添加全局变量/命名空间未被识别.大多数错误的形式为“找不到名字’angular / ionic / ng”(等).

为了使事情变得更加奇怪,我注意到在加载VS Code时最初打开的文件根本没有任何错误.红色下划线错误位于其他选项卡/编辑器中的其他文件中.

这是怎么回事?我如何让VS Code始终如一地承认这些全局/名称空间确实存在?

在追逐这个问题的许多悲伤的日子之后 – 我终于在VS Code GitHub上找到了 GitHub Issue,它解释了发生了什么.

TL;博士

我的tsconfig.json文件配置不正确.为了解决这个问题,我删除文件部分.您可能还需要在项目中删除它,或者只是“修复”它以包含所有相关的.ts文件.

更长的版本

Adding a files [section] limits our project to those two files and if you open other files not referenced by those two files then they end up in an isolated virtual project. You either need to leave out the files section (then all .ts files underneath the tsconfig.json file are automatically considered part of the project) or you need to list all files of your project in that section.

我原来的`tsconfig.json文件是:

{
    "compilerOptions": {
        "target": "es5","sourceMap": true,"removeComments": true,"noImplicitAny": true
    },"files": [
        "typings/index.d.ts","src/typings/index.d.ts"
    ]
}

所以,VS Code认为我的项目只包含两个文件.我加载的其他.ts文件被认为是“孤立的虚拟项目” – 不难理解它们为什么会产生错误.

我将tsconfig.json文件更改为以下内容

{
    "compilerOptions": {
        "target": "es5","noImplicitAny": true
    }
}

问题解决了!

相关文章

ANGULAR.JS:NG-SELECTANDNG-OPTIONSPS:其实看英文文档比看中...
AngularJS中使用Chart.js制折线图与饼图实例  Chart.js 是...
IE浏览器兼容性后续前言 继续尝试解决IE浏览器兼容性问题,...
Angular实现下拉菜单多选写这篇文章时,引用文章地址如下:h...
在AngularJS应用中集成科大讯飞语音输入功能前言 根据项目...
Angular数据更新不及时问题探讨前言 在修复控制角标正确变...