微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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
    }
}

问题解决了!

原文地址:https://www.jb51.cc/angularjs/141240.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐