【发布时间】:2020-11-08 08:32:16
【问题描述】:
在 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语句:
import { SyncService } from '../../services/sync.service';
警告消失。但是警告消息根本不应该出现,因为:
@Injectable({
providedIn: 'root'
})
请看下面的 gif。这是一个错误吗?
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
【问题讨论】:
-
您是否在 tsconfig 文件中添加了实验性装饰器?
-
不,我没有接触过 tsconfig 文件。
-
这应该是设定值:
"experimentalDecorators": true -
刚刚检查,它设置为'true'。该项目是最近使用“ng new”创建的。
-
尝试重启 TypeScript 服务器:
F1 -> TypeScript: Restart TS Server
标签: angular typescript visual-studio-code