我試圖在通過管道(映射)請求后在方法中處理一個 Observable 以使用這個更正的 Observable 來保護。但是在撰寫處理程式時,我遇到了以下錯誤:
Argument of type 'Observable<unknown>' is not assignable to parameter of type 'OperatorFunction<Object, unknown>'.
Type 'Observable<unknown>' provides no match for the signature '(source: Observable<Object>): Observable<unknown>'.
有問題的功能:
isAccessToLobby() {
return this.http
.get(`${environment.domain}${BackendRoutes.Lobby}`, this.httpOptions)
.pipe(map((data) => data.allowAccess));
}
路由器:
router.get("/lobby", isAuth, (req, res) => {
return res.json({
allowAccess: true,
});
});
試圖為引數定義 Observable 型別,但沒有幫助。
uj5u.com熱心網友回復:
正如評論中所討論的,從 rxjs-compat 匯入會導致錯誤。
import { map } from 'rxjs-compat/operator/map';
從 rxjs 匯入 map 函式解決了錯誤。
import { map } from 'rxjs/operators';
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/531385.html
標籤:有角度的打字稿rxjs
上一篇:在primeng表中預選復選框
