0

I got a service in angular7 what gives me back some keys:

  getList(
    pageSize: number = 30,
    pageNumber: number = 0,
    filters: CKeyListFilters = <CKeyListFilters>{},
    sortByKey: string = 'activeTo',
    sortOrder: SortOrder = SortOrder.DESC
  ): Observable<ListPaginated<CKey[]>> {
    // ....

    return this.http
      .get<ListPaginated<CKey[]>>(`${environment.CApiUrl}/Get`, {
        params: params,
        observe: 'response',
      })
      .pipe(
        map((resp: HttpResponse<CKey[]>) => {
          return {
            content: resp.body,
            pagination: this.utilities.getPaginationMetaData(resp),
          } as ListPaginated<CKey[]>;
        }),
        catchError((error) => {
          throw error;
        })
      );
  }

But inside the pipe method I got this error:

error TS2345: Argument of type 'OperatorFunction<HttpResponse<CKey[]>, ListPaginated<CKey[]>>' is not assignable to parameter of type 'OperatorFunction<HttpResponse<ListPaginated<CKey[]>>, ListPaginated<CKey[]>>'.

So I want to map the HttpResponse<CKey[]> to ListPaginated<CKey[]> But I don't know how can I transform it.

I inherited this code and I'm a newbie in typescript, so any suggestion is useful for me!

3
  • Could you please provide the line that imports map? Commented Apr 25, 2019 at 12:49
  • @mbojko sure! Its from import { catchError, map } from 'rxjs/operators'; Commented Apr 25, 2019 at 12:52
  • Oh. My hypothesis was that the wrong map was imported from rxjs. But it appears to be the right one. Commented Apr 25, 2019 at 12:54

1 Answer 1

1

OK. Here it is:

      .get<ListPaginated<CKey[]>>(`${environment.CApiUrl}/Get`, {
        params: params,
        observe: 'response',
      })
      .pipe(
        map((resp: HttpResponse<CKey[]>) => {

in line 1, the requested resource is of type ListPaginated<CKey[]>. In line 6, the map's argument is of type HttpResponse<CKey[]>. Those types must match (or alternatively you can remove resp's typing from the map altogether).

Sign up to request clarification or add additional context in comments.

1 Comment

You are right! :) Thanks. I had to write .get<CKey[]>(...)

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.