我的 tslint 疯了吗?它为我在整个应用程序中所做的每个订阅发出警告。无论我使用旧的还是新的语法都没有关系,它仍然说 subscribe 已被弃用......如何编写一个不会被弃用的订阅?
直到今天还好:
something.subscribe((user: User) => {
this.userProviderService.setUserId(user.userId);
this.proceed = true;
});
我尝试了新语法但没有改变:something.subscribe({
next: (user: User) => {
this.userProviderService.setUserId(user.userId);
this.proceed = true;
},
complete: () => {},
error: () => {}
});
这正是它所说的:(method) Observable.subscribe(next?: (value: Object) => void, error?: (error: any) => void, complete?: () => void): Subscription (+4 overloads) @deprecated — Use an observer instead of a complete callback
@deprecated — Use an observer instead of an error callback
@deprecated — Use an observer instead of a complete callback
subscribe is deprecated: Use an observer instead of a complete callback (deprecation)tslint(1)
那么我现在如何订阅东西?
最佳答案
我刚刚在 VS Code 扩展选项卡中查找了 TSLint (v1.3.3)。它说:
❗IMPORTANT: TSLint has been deprecated in favor of ESLint.
当我禁用 TSLint 并安装 ESLint 时,所有与订阅相关的警告都消失了。
干杯!
关于 Angular 11 : subscribe is deprecated: Use an observer instead?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66604826/