【问题标题】:Suppress Angular Language Service VSCode extension's "strictTemplates in angularCompilerOptions" notification抑制 Angular 语言服务 VSCode 扩展的“angularCompilerOptions 中的strictTemplates”通知
【发布时间】:2021-05-26 17:46:53
【问题描述】:

由于我们将代码库升级到 Angular 11,我在 VSCode 中收到了这条消息:

某些语言功能不可用。要访问所有功能,请在angularCompilerOptions 中启用strictTemplates

来源:Angular 语言服务(扩展)

带有“打开 tsconfig.json”的链接,如下所示:

我期待启用此功能并享受新功能。但我想抽出时间来做和测试。目前,VSCode 中的弹出窗口一直在出现,这既烦人又让人分心。

我如何(暂时)禁止显示此消息,最好是针对我当前的工作区?


  • Angular 语言服务 (angular.ng-template) v11.2.3
  • Windows 10 上的 Visual Studio Code 版本 1.53.2

【问题讨论】:

    标签: angular visual-studio-code angular-language-service


    【解决方案1】:

    如果为工作区创建 .code-workspace 文件,则可以添加以下内容以禁用提示:

        "settings": {
            "angular.enable-strict-mode-prompt": false
        }
    

    注意:如果你打开工作区,上面显示的提示应该有一个额外的按钮来为你添加这个设置:

    【讨论】:

      【解决方案2】:

      在 Angular 12 中,Ivy 是默认引擎。当您在本地安装了版本 11 并且您的 Angular 语言服务扩展在版本 12 中时,您开始收到该消息,选项是将您的 angular(和依赖项)的本地副本更新到版本 12 并配置编译器,或者安装如上面的一些答案所示,较低版本的 Angular 语言服务。

      或在 Angular 语言服务中单击该选项

      当然不鼓励这样做。因为未来是常春藤:)。但在社区和不同依赖项之间的一切准备就绪之前,这是一个临时选项

      【讨论】:

        【解决方案3】:

        从根位置打开tsconfig.json 文件。 添加"strictTemplates": true

        这是 tsconfig.json 的样子:

        /* To learn more about this file see: https://angular.io/config/tsconfig. */
        {
          "compileOnSave": false,
          "compilerOptions": {
            "baseUrl": "./",
            "outDir": "./dist/out-tsc",
            "sourceMap": true,
            "declaration": false,
            "downlevelIteration": true,
            "experimentalDecorators": true,
            "moduleResolution": "node",
            "importHelpers": true,
            "target": "es2015",
            "module": "es2020",
            "lib": ["es2018", "dom"]
          },
          "angularCompilerOptions": {
            "enableI18nLegacyMessageIdFormat": false,
            "strictTemplates": true
          }
        }
        

        【讨论】:

          【解决方案4】:

          对于 Angular 10+

          只需添加以下几行:

          "angularCompilerOptions": {
          
             "fullTemplateTypeCheck": true,
             "preserveWhitespaces": true
          
          }
          

          更多,这里是文档:Doc

          【讨论】:

            【解决方案5】:

            这是引入此警告的 PR: https://github.com/angular/vscode-ng-language-service/pull/1097

            您的项目是否使用多个.tsconfig 文件?我相信每次发现新的.tsconfig 时,Angular 语言服务都需要重新启动,这会触发此错误。我将研究为什么没有永久抑制错误的选项。

            【讨论】:

            • 我们确实有.tsconfig 文件。根中的一个基数,以及extends 基数的每个 Angular(应用程序)项目中的一个。目前在strictTemplates 中没有提到任何地方,还没有尝试过明确地使用false
            • @Jeroen 所以由于.tsconfigs 管理路径的性质,没有项目级别.tsconfig 的概念——并且扩展无法获得所有相关的.tsconfigs没有有效地编译程序。我将做一个 PR 以提供在全球范围内使警告静音的选项。
            【解决方案6】:

            大家好,我也遇到了同样的问题,但我做了这个,但该消息停止显示......我希望能帮助我们。

            tsconfig.json

            {
              "extends": "../../tsconfig.json",
              "compilerOptions": {
                "types": ["node", "jest"]
              },
              "include": [...],
              "angularCompilerOptions": {
                "strictTemplates": true
              }
            }
            

            Configuration

            【讨论】:

            • 感谢分享!这打开 strictTemplates 的功能,对吗?你在一个大项目上做过吗,它有没有遇到任何问题? - 我还不想这样做(我的项目是 10s of 1000s of LoC)
            • 嗨 @Jeroen,是的,我在一个大型项目中激活了它,唯一可能给我带来一些问题的是 Formly 库,因为它具有 Angular 的 FormsControl 的自定义对象
            【解决方案7】:

            我遇到了同样的问题,安装 Angular Extension Pack 后它似乎消失了。

            【讨论】:

            • 感谢您的回复!你的意思是this pack?那里有 的扩展程序,很想知道哪个扩展程序实际上抑制了警告,而不是热衷于安装 20ish 扩展程序来抑制警告。
            • 今天将我的 Visual Studio 代码更新到版本:1.54.1 后,我遇到了类似的问题。除了安装 Angular 扩展包之外,还有其他方式解决了吗?
            • 作为一种解决方法,它有所帮助,但它仍然显示通知,所以这可能只是部分解决方案
            猜你喜欢
            • 2018-12-12
            • 2012-10-26
            • 1970-01-01
            • 1970-01-01
            • 2017-03-10
            • 1970-01-01
            • 2017-05-13
            • 2018-01-08
            • 2019-06-20
            相关资源
            最近更新 更多