问题描述
我的 tslint 疯了?它为我在整个应用程序中所做的每个订阅发出警告.无论我使用旧的还是新的语法都没有关系,它仍然说 subscribe 已被弃用...如何编写一个不会被弃用的订阅?
My tslint gone crazy? It gives warning for every subscribtion I made in whole app. It doesn't matter if I use old or new syntax it still says that subscribe is deprecated... How to write a subscription that will not be deprecated?
直到今天还好:
something.subscribe((user: User) => {
this.userProviderService.setUserId(user.userId);
this.proceed = true;
});
我尝试了新语法但没有改变:
I tried new syntax but makes no change:
something.subscribe({
next: (user: User) => {
this.userProviderService.setUserId(user.userId);
this.proceed = true;
},
complete: () => {},
error: () => {}
});
这正是它所说的:
(method) Observable.subscribe(next?: (value: Object) => void,错误?:(错误:任何)=>无效,完整?:() =>无效):订阅(+4重载) @deprecated — 使用观察者而不是完整的回调
@deprecated — 使用观察者而不是错误回调
@deprecated — Use an observer instead of an error callback
@deprecated — 使用观察者而不是完整的回调
@deprecated — Use an observer instead of a complete callback
subscribe 已弃用:使用观察者而不是完整的回调(弃用)tslint(1)
subscribe is deprecated: Use an observer instead of a completecallback (deprecation)tslint(1)
那么我现在如何订阅东西?
So how do I subscribe to things now?
推荐答案
我刚刚在 VS Code 扩展选项卡中查找了 TSLint (v1.3.3).它说:
I just looked up TSLint (v1.3.3) at VS Code extenstions tab. It says:
❗重要提示:TSLint 已被弃用,取而代之的是 ESLint.
当我禁用 TSLint 并安装 ESLint 时,所有与订阅相关的警告都消失了.
As I disabled TSLint and installed ESLint, all warnings related to subscribtions dissapeared.
干杯!
这篇关于Angular 11:订阅已弃用:改用观察者?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!