禁止 Angular 语言服务 VSCode 扩展的 "strictTemplates in angularCompilerOptions" 通知

Suppress Angular Language Service VSCode extension's "strictTemplates in angularCompilerOptions" notification

自从我们将代码库升级到 Angular 11 后,我在 VSCode 中收到此消息:

Some language features are not available. To access all features, enable strictTemplates in angularCompilerOptions.

Source: Angular Language Service (Extension)

用link来“打开tsconfig.json”,像这样:

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

我如何(暂时)抑制此消息,最好是针对我当前的工作区?


我遇到了同样的问题,安装 Angular 扩展包后似乎消失了。

大家好,我遇到了同样的问题,但我这样做了,但那条消息不再显示了……希望对我们有所帮助。

tsconfig.json

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

Configuration

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

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

对于Angular 10+ :

只需添加以下行:

"angularCompilerOptions": {

   "fullTemplateTypeCheck": true,
   "preserveWhitespaces": true

}

有关更多信息,请参阅文档:Doc

从根位置打开 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
  }
}

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

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

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

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

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

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