0

This line of typescript code is throwing an error when transpiling.

  getXXX(): Observable<any> {
    return this.http.get('api/xxx').catch(err => {return err});
  }

The error is

Supplied parameters do not match any signature of call target

I have the following imports in my script

import {Observable} from "rxjs/Rx";
import 'rxjs/add/operator/catch';

How doI fix it

3
  • 1
    You have an extra closing parenthesis ). Also, you can just import Observable instead of the whole lib: import {Observable} from "rxjs/Observable"; Commented May 15, 2017 at 2:39
  • Corrected my question, the new import did not help Commented May 15, 2017 at 2:44
  • What you have is not a valid error handler in any case. Don't catch errors in parts of your program with insufficient context to handle them. Returning error is invalid. Remove the catch. Commented May 15, 2017 at 5:44

1 Answer 1

1

this is syntax error for Typescript. When arrow function has {}, in {} there must have a return, relevant link.

this.http.get('api/xxx').catch(err => { return err; });

or simply not use {}

this.http.get('api/xxx').catch(err => err);
Sign up to request clarification or add additional context in comments.

4 Comments

I still have the same error after making suggested changes
@Sridhar can you post the entire function where you called this.http.get?
@Sridhar or else, are you setting any other parameters to this.http.get?
@Sridhar mm.... your code looks fine this time. are you sure the error is on this http.get line?

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.