简体   繁体   English

Typescript 弃用警告

[英]Typescript Deprecation warning

I am using this code for login but subscribe shows depricated.我正在使用此代码进行登录,但订阅显示已被贬低。 I am new to typescript, so can anyone help me out我是 typescript 的新手,所以谁能帮帮我

doLogin() 
{
  
     this.userService.doLogin(this.loginForm.value).subscribe(
     result => 
     {
     console.log(result);
     localStorage.setItem('userData', JSON.stringify(result));
     this.router.navigate(['/list-user']);
     this.toastr.success('Success', 'Logged In Successfully');
     },
     (error) => 
     {
     console.log(error);
     this.toastr.error('Failed', 'Invalid Credentials');
     });
}

this works in an other project I've worked on but shows depricated here and I'm getting this error:这在我从事的另一个项目中有效,但在这里显示被贬低,我收到了这个错误:

@deprecated — Instead of passing separate callback arguments, use an observer argument. @deprecated — 不要传递单独的回调 arguments,而是使用观察者参数。 Signatures taking separate callback arguments will be removed in v8.采用单独回调 arguments 的签名将在 v8 中删除。 Details: https://rxjs.dev/deprecations/subscribe-arguments详细信息: https://rxjs.dev/deprecations/subscribe-arguments

'(next?: ((value: Object) => void) | null | undefined, error?: ((error: any) => void) | null | undefined, complete?: (() => void) | null | undefined): Subscription' is deprecated.ts(6385) Observable.d.ts(55, 9): The declaration was marked as deprecated here. '(next?: ((value: Object) => void) | null | undefined, error?: ((error: any) => void) | null | undefined, complete?: (() => void) | Z37B978EZADA1 | undefined): Subscription' is deprecated.ts(6385) Observable.d.ts(55, 9): 声明在此处被标记为已弃用。

As per the link根据链接

import { of } from 'rxjs';
// recommended 
of([1,2,3]).subscribe((v) =>         
console.info(v));
// also recommended
of([1,2,3]).subscribe({
    next: (v) => console.log(v),
    error: (e) => console.error(e),
    complete: () =>     
        console.info('complete') 
})

You will no longer need to pass more than one callback.您将不再需要传递多个回调。 If needed you can pass in an observable object containing the callbacks.如果需要,您可以传入包含回调的可观察 object。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Angular Typescript错误-不推荐使用字符集。 (弃用) - Angular Typescript Error - charset is deprecated. (deprecation) 解决Angular App中的Moment.js弃用警告 - Resolving Moment.js Deprecation Warning in Angular App WEBPACK 弃用数组以在 angular 11 中使用 web 包 5 设置警告 - WEBPACK deprecation array to set warning in angular 11 using web pack 5 TypeScript错误警告,但是可以 - TypeScript error warning, but it works Angular 9 警告 typescript.js - Angular 9 Warning typescript.js 在全新的 Angular 11 应用程序中运行单元测试时,我收到以下弃用警告: - I'm getting the following deprecation warning when running unit tests in a brand new Angular 11 application: Angular 通过 formGroup + ngModel 使用的反应式表单验证:弃用的致命警告 + 移除支持? - Angular reactive form validation through formGroup + ngModel usage: Fatal warning of deprecation + removal of support? 更新Angular 6到7 - 依赖性警告和打字稿错误 - Update Angular 6 to 7 - dependency warning and typescript error 如何在Angular 2 Typescript的Webclipse中自定义格式警告? - How to customize formatting warning in Webclipse for Angular 2 Typescript? RxJS、Typescript 和可怕的“类型不匹配”警告/错误 - RxJS, Typescript and the dreaded 'Type Mismatch' warning/error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM