I would like to use a service but I get this error:
TS2345: Argument of type 'Partial<{ email: string | null; password: string | null; }>' is not assignable to parameter of type 'Login'.
Types of property '"email"' are incompatible. Type 'string | null | undefined' is not assignable to type 'string'. Type 'undefined' is not assignable to type 'string'.
Service
public login(data: Login): Observable<string> {
return this.httpClient.post<string>(environment.apiUrl + '/login', data);
}
Interface
export interface Login {
"email": string,
"password": string
}
Component
export class LoginComponent implements OnInit {
loginForm = this.fb.group({
'email': ['', [Validators.email, Validators.required]],
'password': ['', Validators.required]
})
constructor(private loginService: LoginService, private fb: FormBuilder) { }
ngOnInit(): void {
}
submit() {
this.loginService.login(this.loginForm.value).subscribe(response => {
// Do sumth
})
}
}
Is there something wrong with my interface, or should the parameter data have another data type?