Reputation: 23
I'm working with Angular 5 and Spring Backend. In a request I'm return a string.
Backend code:
@PostMapping(value = "login")
public ResponseEntity<?> verifyLogin(@RequestBody String login){
System.out.println("LOGIN REALIZADO");
LoginObject loginO = gson.fromJson(login, LoginObject.class);
if(verify(loginO)){
return new ResponseEntity<String>("AAA",HttpStatus.OK);
}else{
return new ResponseEntity<String>("ERROR-LOGIN",HttpStatus.OK);
}
}
As you can see, I return AAA or ERROR-LOGIN.
And in my frontend I receive this using this code:
loginQuery(login: Login):Observable<string>{
return this.http.post<string>('http://localhost:8080/login',JSON.stringify(login),{ responseType: 'text' as 'text'});
}
This is working fine. Because I can print AAA in console of my browser. But... the console (of Intellij) shows this error:
ERROR in src/app/login/sevices/login.service.ts(15,68): error TS2345: Argument of type '{ responseType: "text"; }' is not assignable to parameter of type '{ headers?: HttpHeaders | { [header: string]: string | string[]; }; observe?: "body"; params?: Ht...'. Types of property 'responseType' are incompatible. Type '"text"' is not assignable to type '"json"'.
And my program stops running. What I can do? I need receive this string and work with it.
Upvotes: 0
Views: 1150
Reputation:
You should create headers, not give a random object to it.
Or, you can type your random object as any, to bypass the error (nastier but easier).
return this.http.post<string>('URL', {}, { responseType: 'text'} as any);
Upvotes: 4