【发布时间】:2019-04-25 12:35:52
【问题描述】:
我在 angular7 中获得了一项服务,它给了我一些密钥:
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;
})
);
}
但是在pipe 方法中我得到了这个错误:
error TS2345: Argument of type 'OperatorFunction<HttpResponse<CKey[]>, ListPaginated<CKey[]>>' is not assignable to parameter of type 'OperatorFunction<HttpResponse<ListPaginated<CKey[]>>, ListPaginated<CKey[]>>'.
所以我想将HttpResponse<CKey[]> 映射到ListPaginated<CKey[]> 但我不知道如何转换它。
我继承了这段代码,我是typescript 的新手,所以任何建议对我都有用!
【问题讨论】:
-
能否提供导入
map的行? -
@mbojko 当然!来自
import { catchError, map } from 'rxjs/operators'; -
哦。我的假设是错误的
map是从 rxjs 导入的。但它似乎是正确的。
标签: angular typescript httpclient angular7