How can I resolve this Angular error:
(response: HttpResponse<User>) => {
which results in the following error message:
Argument of type '(response: HttpResponse<User>) => void' is not assignable to parameter of type '(value: HttpResponse<User> | HttpErrorResponse) => void'.
Types of parameters 'response' and 'value' are incompatible.
Type 'HttpResponse<User> | HttpErrorResponse' is not assignable to type 'HttpResponse<User>'.
Type 'HttpErrorResponse' is missing the following properties from type 'HttpResponse<User>': body, clone
ALSO
(response.body);
raises the following error:
Argument of type 'User | null' is not assignable to parameter of type 'User'.
Type 'null' is not assignable to type 'User'.
I am currently using TypeScript 4.5.5 in my Angular project.
The function causing the issue is:
public onLogin(user: User): void{
console.log(user)
this.subscriptions.push(
this.authenticationService.login(user).subscribe(
(response: HttpResponse<User>) => {
const token: string = response.headers.get(HeaderType.JWT_TOKEN) || '';
this.authenticationService.saveToken(token);
this.authenticationService.addUserToLocalCache(response.body);
this.router.navigateByUrl('/dashboard');
},
(error: HttpErrorResponse) => {
console.log(error);
this.sendErrorNotification(NotificationType.ERROR, error.error.message);
}
)
);
}
NOTE: This function worked without issues in a previous project with a different version of TypeScript.