angular - VS 代码- Angular : Experimental support for decorators Warning

标签 angular typescript visual-studio-code

在 Angular (v10) 项目中创建一个空白文件 (sync.service.ts) 并添加以下代码:

import { Injectable } from '@angular/core';

@Injectable({
    providedIn: 'root'
})
export class SyncService {

}

给出这个警告:

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.

我打开了一个随机文件(tag-cloud.component.ts)并添加了一条导入语句:

import { SyncService } from '../../services/sync.service';

警告消失。但警告消息根本不应该出现,因为:

@Injectable({
    providedIn: 'root'
})

请看下面的 gif。这是一个错误吗?

enter image description here

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

最佳答案

出现“问题”是因为 Typescript 3.9 和 Angular 10 附带的 tsconfig 文件(解决方案样式 tsconfig)发生了变化。

更多信息在这里:

https://github.com/microsoft/TypeScript/issues/39632

https://docs.google.com/document/d/1eB6cGCG_2ircfS5GzpDC9dBgikeYYcMxghVH5sDESHw/edit#

解决方案样式 tsconfig 对 Angular 10 的影响

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. In Angular CLI version 10 we adopted scaffolded new and migrated existing workspaces to use solution-style Typescript configuration.

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.

  1. 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.

    Below find an example of changes that will be required in the application tsconfig file (tsconfig.app.json). Changes to other tsconfig files will also be needed.

Current tsconfig.app.json

{
 "extends": "./tsconfig.base.json",
 "compilerOptions": {
   ...
 },
 "files": [
   "src/main.ts",
   "src/polyfills.ts"
 ],
 "include": [
   "src/**/*.d.ts"
 ]
}

Proposed tsconfig.app.json

{
 "extends": "./tsconfig.base.json",
 "compilerOptions": {
   ...
 },
 "include": [
   "src/**/*.ts"
 ],
 "exclude": [
   "src/test.ts",
   "src/**/*.spec.ts",
   "src/**/*.server*",
   "src/**/*.worker.ts"
 ]
}

关于angular - VS 代码- Angular : Experimental support for decorators Warning,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62972535/

相关文章:

typescript - 将 Sequelize.Instance 与 Sequelize v5 和 Typescript 一起使用

firebase - 我可以评论 firebase.json 文件吗?

c++ - 为什么当从 VSCode 使用 GDB 时遇到断点时,GDB 会使我的程序崩溃?

html - 无法将单选按钮与标签分开

javascript - 刷新 Angular 中的特定组件

javascript - 在 VS 中,有没有办法忽略某些 typescript 文件上的错误但仍将它们编译进去?

html - PrimeNG 组件菜单步骤,我如何使用 ui-steps-incomplete

node.js - 在 Linux Ubuntu 的 Windows 子系统中链接 Windows 命令

c# - 数字组合

javascript - 无法读取未定义的属性 'date'