我是新手;请忍受我。
我需要获取id的ID列表=> this.getIds()并使用mergeMap()为ID列表中的每个ID获得其名称=> getNames(id)。有人可以在下面检查我做错了什么(无法编译)吗?
interface Id{
"Id": string;
"Name": string;
}
export interface Ids extends Array<Id>{}
在myservice.ts
getIds():Ids {
return this.http
.post(url1, '')
.pipe(map(({ Ids}: Ids) => Ids.map(item => ({Id: item.Id }))));
}
getNames():Observable<any[]> {
return this.http
.post(url2, '')
.pipe(map(({ Names }: any) => Names.map(item => ({Sid: item.Id, Name: item.Name }))));
}
在mycomponent.ts中,
getIds(): void {
this.myservice
.getIds.pipe(
mergeMap(id => this.getNames(id)),
mergeMap(names => names),
toArray()
)
}
getNames(): void {
this.myservice
.getNames(ids)
.subscribe(val => this.data = val);
}
ERROR in src/app/myservice.ts(24,5): error TS2322: Type 'Observable<any>' is not assignable to type 'Ids'.
Property 'includes' is missing in type 'Observable<any>'.
src/app/myservice.ts(26,17): error TS2459: Type 'Ids' has no property 'Ids' and no string index signature.
src/app/mycomponent.ts(128,20): error TS2339: Property 'pipe' does not exist on type '() => Ids'.
src/app/mycomponent.ts(129,35): error TS2345: Argument of type '{}' is not assignable to parameter of type 'Ids'.
Property 'includes' is missing in type '{}'. src/app/mycomponent.ts(130,19): error TS2345: Argument of type '(vulns: {}) => {}' is not assignable to parameter of type '(value: {}, index: number) => ObservableInput<{}>'.
Type '{}' is not assignable to type 'ObservableInput<{}>'.
Type '{}' is not assignable to type 'Iterable<{}>'.
Property '[Symbol.iterator]' is missing in type '{}'.