Error TS2346: Delivered parameters do not match any target call signature

I am new to Typescript and Angular2, and I am trying to create a promise by requesting http get, but the code below (exactly the return this.http.get(url) line return this.http.get(url) gives me an error:

error TS2346: Supplied parameters do not match any signature of call target.

In my service, I have an isLoggedIn method

 isLoggedIn(): Promise<Object> { return this.http.get('/some/path') .map((res: Response) => res.json()) .toPromise(); } 

Then I want to use it in my component, for example:

 onInit() { this.login.isLoggedIn() .then((data: any) => { if (data.hasOwnProperty('status') && data.status === 401) { this.router.navigate(['/Login']); } else { this.router.navigate(['/Home']) } }); } 

I looked at how to use the HTTP request and promise the correct path, but I did not find a good description.

+5
source share
1 answer

Quick search for Angular source:

static toPromise(obj: Observable<any>): Promise<any> { return (<any>obj).toPromise(); }

Indicates that the toPromise method should receive an Observable<any> (your call was: toPromise() )

I assume this is causing the error

0
source

Source: https://habr.com/ru/post/1235899/


All Articles