在某些情况下(例如角度和离子),问题是通过包含Angular / Ionic而添加的全局变量/命名空间未被识别.大多数错误的形式为“找不到名字’angular / ionic / ng”(等).
为了使事情变得更加奇怪,我注意到在加载VS Code时最初打开的文件根本没有任何错误.红色下划线错误位于其他选项卡/编辑器中的其他文件中.
这是怎么回事?我如何让VS Code始终如一地承认这些全局/名称空间确实存在?
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.
{ "compilerOptions": { "target": "es5","sourceMap": true,"removeComments": true,"noImplicitAny": true },"files": [ "typings/index.d.ts","src/typings/index.d.ts" ] }
所以,VS Code认为我的项目只包含两个文件.我加载的其他.ts文件被认为是“孤立的虚拟项目” – 不难理解它们为什么会产生错误.
{ "compilerOptions": { "target": "es5","noImplicitAny": true } }
问题解决了!
原文地址:https://www.jb51.cc/angularjs/141240.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。