Reputation: 87
I cannot build my Angular4 project because of that error that I really don't understand. I have my imports like Response, Headers, Http from @angular. When I'm trying to build my project I get this error:
TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. Type argument candidate 'Response' is not a valid type argument because it is not a supertype of candidate 'Response'. Types of property 'type' are incompatible. Type 'string' is not assignable to type 'ResponseType'.
It refers to this code:
public getPatients(): Observable<any> {
//noinspection TypeScriptValidateTypes
return this.http.get(AppSettings.API_ENDPOINT + 'patient', { headers: this.getHeaders() })
.map((res:Response) => res.json())
.catch((error) => Observable.throw(error.json().error || "Server error"));
}
I found a workaround with imports and I added all mentioned in those threads but it still doesn't help.
Upvotes: 3
Views: 259
Reputation: 58
I had the same problem and i found out that the problem was that i did not import the right things.
try using these :
import {Http, Response} from "@angular/http";
import 'rxjs/add/operator/map'
import 'rxjs/add/operator/catch';
import {Observable } from "rxjs/Observable";
Upvotes: 2
Reputation: 557
If have code like this :
editItem(item: Item) {
return this.http.put(`${this.BACKOFFICE_URL}`, item, this.getOptions())
.map((res: Response) => {
return res.status === 200 ? res.json() : {};
})
.catch((error: any) => {
return Observable.throw(error);
})
}
The only difference I see with your code is that I don't put a return type to the function.
Upvotes: 0