error TS2558: Expected 0 type arguments, but got 1 - Angular

0

Good afternoon, my problem is this:

I am receiving an error in each of the calls I make to the REST service. This error disappears changing anything in the code (including just "//" for example), but the first time it compiles it always fails.

I would like to know if someone understands the problem.

As I said before, the code works. But it fails the first time. Here is an example:

/** GET carsfrom the server */
    getCars(): Observable<Car[]> {
        return this.http.get<Car[]>(this.carsUrl)
            .map(response => {
                let res = response.json().cars;
                if (!Array.isArray(res)) {
                    return [res]
                }
                return res;
            })
            .pipe(
            catchError(this.handleError('getCars Error', []))
            );
    }

The error occurs in the first line of the return. The error produced is as follows:

TS2558 error: Expected 0 type arguments, but got 1.

    
asked by Mario López Batres 08.12.2017 в 14:08
source

1 answer

0

The problem was that it specified a type when performing the operation. In this case, the type was System

Final code

/** GET carsfrom the server */
    getCars(): Observable<Car[]> {
        return this.http.get(this.carsUrl)
            .map(response => {
                let res = response.json().cars;
                if (!Array.isArray(res)) {
                    return [res]
                }
                return res;
            })
            .pipe(
            catchError(this.handleError('getCars Error', []))
            );
    }

Removed

this.http.get/*<Car[]>*/
    
answered by 08.12.2017 в 17:24