3

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.

1
  • Can you split your return statement, introducing a variable for the http.get().map(), and tell us what line produces the error? I suspect the inferred type of the returned value of the catch(). Commented Oct 1, 2017 at 11:42

2 Answers 2

2

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";
Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.