Types of property 'responseType' are incompatible
Here is an approach if you don't want to remove <string>
to keep your response strongly typed:
const httpOptions = {
headers: new HttpHeaders({
'Accept': 'text/plain, */*',
'Content-Type': 'application/json' // We send JSON
}),
responseType: 'text' as 'json' // We accept plain text as response.
};
return this.http.post<string>(this.setBaseUrl, body, httpOptions);
Replace text
with valid responseType according the data that you want to receive.
The version of post
accepting responseType:'text'
is not generic, since the result type is already clear (ie string
)
this.http
.post(this.loginUrl, this.user, {responseType: 'text'}) // no generic parameter
.subscribe(
(data) => this.success(data), // data is string
(error) => this.failure(error)
);
I just ran into this particular issue today myself. After searching for a little and figuring that the responseType option should exist, I managed to get it work as below:
let requestOptions: Object = {
headers: new HttpHeaders().set('Authorization', 'Basic ' + credentials),
responseType: 'text'
}
return this.httpClient.get<any>(
this.environment.tokenHost + this.environment.authenticationURL,
requestOptions
)
.subscribe(result => {
// do stuff
});
Setting the responseType
like that makes it work, compared to configuring it in the 'request' itself.
Regards.
Just remove "string" from your request. Try this:
this.http.post(this.loginUrl, this.user, {responseType: 'text'}).subscribe(
(data) => this.success(data),
(error) => this.failure(error)
);