[英]VS Code - Angular: Experimental support for decorators Warning
In an Angular (v10) project creating a blank file (sync.service.ts) and adding this code:在 Angular (v10) 项目中创建一个空白文件 (sync.service.ts) 并添加以下代码:
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class SyncService {
}
gives this warning:给出这个警告:
Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option in your 'tsconfig' or 'jsconfig' to remove this warning.
I opened a random file (tag-cloud.component.ts) and added an import statement:我打开了一个随机文件(tag-cloud.component.ts)并添加了一个导入语句:
import { SyncService } from '../../services/sync.service';
The warning goes away.警告消失。 But the warning message shouldn't appear at all because of:
但是警告消息根本不应该出现,因为:
@Injectable({
providedIn: 'root'
})
Please see the gif below.请看下面的gif。 Is this a bug?
这是一个错误吗?
Version: 1.47.1
Commit: 485c41f9460bdb830c4da12c102daff275415b53
Date: 2020-07-14T00:13:57.513Z
Electron: 7.3.2
Chrome: 78.0.3904.130
Node.js: 12.8.1
V8: 7.8.279.23-electron.0
OS: Linux x64 5.4.0-40-generic
This is a bizarre behaviour I have also come across with WebStorm.这是我在使用 WebStorm 时也遇到的一种奇怪行为。 All I can say is that after a while (couldn't tell you what triggers the IDE to understand properly), the warning disappears and everything goes back to normal.
我只能说,过了一会儿(无法告诉您是什么触发了 IDE 正确理解),警告消失,一切恢复正常。
The 'problem' arises because of the change in tsconfig files (solutions style tsconfig) that comes with Typescript 3.9 and Angular 10.出现“问题”的原因是 Typescript 3.9 和 Angular 10 附带的 tsconfig 文件(解决方案样式 tsconfig)发生了变化。
More info here:更多信息在这里:
https://github.com/microsoft/TypeScript/issues/39632 https://github.com/microsoft/TypeScript/issues/39632
https://docs.google.com/document/d/1eB6cGCG_2ircfS5GzpDC9dBgikeYYcMxghVH5sDESHw/edit# https://docs.google.com/document/d/1eB6cGCG_2ircfS5GzpDC9dBgikeYYcMxghVH5sDESHw/edit#
Solution style tsconfig impact in Angular 10 Angular 10 中的解决方案样式 tsconfig 影响
In TypeScript 3.9, the concept of solutions style tsconfig was introduced, in Angular we saw the potentiation and possibility of fixing long outstanding issues such as incorrectly having test typings in components files.
在 TypeScript 3.9 中,引入了解决方案样式 tsconfig 的概念,在 Angular 中,我们看到了修复长期悬而未决的问题的能力和可能性,例如组件文件中的测试类型错误。 In Angular CLI version 10 we adopted scaffolded new and migrated existing workspaces to use solution-style Typescript configuration.
在 Angular CLI 版本 10 中,我们采用了脚手架新工作区和迁移现有工作区,以使用解决方案式 Typescript 配置。
When having an unreferenced file, this will not be part of any TypeScript program, this is because Angular CLI scaffolds tsconfig using the files option as opposed to include and exclude.
当有一个未引用的文件时,这不会是任何 TypeScript 程序的一部分,这是因为 Angular CLI 使用文件选项而不是包含和排除来构建 tsconfig。
Unreferenced files don't inherit compiler options
未引用的文件不继承编译器选项
When having an unreferenced file, this will not be part of any TypeScript program and Language service will fallback to use the inferred project configuration.
当有一个未引用的文件时,这将不是任何 TypeScript 程序的一部分,并且语言服务将回退以使用推断的项目配置。
Below find an example of changes that will be required in the application tsconfig file (tsconfig.app.json).
下面是应用程序 tsconfig 文件 (tsconfig.app.json) 中所需更改的示例。 Changes to other tsconfig files will also be needed.
还需要更改其他 tsconfig 文件。
Current tsconfig.app.json
当前 tsconfig.app.json
{ "extends": "./tsconfig.base.json", "compilerOptions": {... }, "files": [ "src/main.ts", "src/polyfills.ts" ], "include": [ "src/**/*.d.ts" ] }
Proposed tsconfig.app.json
建议 tsconfig.app.json
{ "extends": "./tsconfig.base.json", "compilerOptions": {... }, "include": [ "src/**/*.ts" ], "exclude": [ "src/test.ts", "src/**/*.spec.ts", "src/**/*.server*", "src/**/*.worker.ts" ] }
A comment at the end of the first post in @Wolf359's answer led me to a simple workaround, in the event that your issue is cause by the tsconfig.json
being split into tsconfig.base.json
and tsconfig.app.json
: add a tsconfig.json
consisting solely of { "extends": "./tsconfig.base.json" }
(I have commented likewise on his link as well). A comment at the end of the first post in @Wolf359's answer led me to a simple workaround, in the event that your issue is cause by the
tsconfig.json
being split into tsconfig.base.json
and tsconfig.app.json
: add a tsconfig.json
仅由{ "extends": "./tsconfig.base.json" }
组成(我也对他的链接发表了同样的评论)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.