gpt4 book ai didi

javascript - 类型 'subscribe' 上不存在属性 'OperatorFunction'

转载 作者:行者123 更新时间:2023-12-01 00:31:36 35 4
gpt4 key购买 nike

我知道之前已经多次询问过这个问题,但是,我无法弄清楚如何使用以下帖子更改我自己的代码。

Property 'subscribe' does not exist on type 'OperatorFunction<Response, Recipe[]>'

Property 'subscribe' does not exist on type 'OperatorFunction<Product[], ParamMap>'

Property 'subscribe' does not exist on type 'OperatorFunction<unknown, any>'

<小时/>

rest-api.service.ts

specificObjectRequest(ids: string[]): Observable<any> {
var idString = ids.join();
const url = `${ApiServerUrl}/media_objects?ID=${idString}`;
console.log("requesting from url: " + url);
this.http.get(url, {}, {})
.then(res => this.extractData = res.data)
.catch(this.handleError);
return;
}

tagRequest(topic: string){
var url = `${ApiServerUrl}/tags?topic=${topic}`;
url = encodeURI(url);
console.log("requesting from url: " + url);
this.http.get(url, {}, {})
.then(res => this.extractData = res.data)
.catch(this.handleError);
return map(this.extractData);
}

我使用官方文档https://ionicframework.com/docs/native/http创建了这个请求和本教程

filter.page.ts

async requestMapTags(topic: string){
await this.api.tagRequest(topic).subscribe(res => { //Property 'subscribe' does not exist on type 'OperatorFunction<Response, {}>'
console.log(res);
this.tagsRequestAnswer = res;
}, err => {
console.log(err);
});
}

错误消息:

[ng] ERROR in src/app/filter/filter.page.ts(89,35): error TS2339: Property 'subscribe' does not exist on type 'OperatorFunction<Response, {}>'.

据我所知,这是 Promises 和 rxjs 之间的冲突。

问题:我需要更改什么才能使其正常工作?有没有办法在我的代码中添加所需的“管道”函数以使其正常工作?

最佳答案

这里使用 promise 似乎没有必要,你可以更轻松地做到这一点

import { of } from 'rxjs';

tagRequest(topic: string){
var url = `${ApiServerUrl}/tags?topic=${topic}`;
url = encodeURI(url);
return of(this.http.get(url, {}, {})).pipe(map(res => res.data));
}

requestMapTags(topic: string){
this.api.tagRequest(topic).subscribe(res => {
console.log(res);
this.tagsRequestAnswer = res;
}, err => {
console.log(err);
});
}

关于javascript - 类型 'subscribe' 上不存在属性 'OperatorFunction<Response, {}>',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58485082/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com