如何返回不同类型的可观察值
我有一个可观察的方法,它返回一些数据,我需要从另一个可观察的方法订阅它,但我收到错误
public getSessionInfo(): Observable<UserInfo> {
return this.getUserDetails().subscribe((data: any) => {
return of({
userId: data.UserID,
tenantId: data.tenantID,
launchDarklySecureModeHash: '',
roles: [''],
emailId: data.EmailID,
tenantName: data.name,
userName: data.UserName,
pendoJWTToken: '',
location: '/',
displayLocation: ''
})
});
}
我收到错误,订阅缺少 UserInfo 的 Observable 类型的以下属性,但是代码部分
return of({
userId: data.UserID,
tenantId: data.tenantID,
launchDarklySecureModeHash: '',
roles: [''],
emailId: data.EmailID,
tenantName: data.name,
userName: data.UserName,
pendoJWTToken: '',
location: '/',
displayLocation: ''
})
的类型与是可观察的 UserInfo 但我无法解决这个问题。 请有人建议解决方案,并记下我无法对 getSessionInfo 方法的类型进行任何更改,因为它是覆盖方法。
提前致谢。
I have a observable method which is return some data I need to subscribe this from another observable method but I am getting error
public getSessionInfo(): Observable<UserInfo> {
return this.getUserDetails().subscribe((data: any) => {
return of({
userId: data.UserID,
tenantId: data.tenantID,
launchDarklySecureModeHash: '',
roles: [''],
emailId: data.EmailID,
tenantName: data.name,
userName: data.UserName,
pendoJWTToken: '',
location: '/',
displayLocation: ''
})
});
}
I am getting error that subscription is missing the following properties of type Observable of UserInfo, however the code section
return of({
userId: data.UserID,
tenantId: data.tenantID,
launchDarklySecureModeHash: '',
roles: [''],
emailId: data.EmailID,
tenantName: data.name,
userName: data.UserName,
pendoJWTToken: '',
location: '/',
displayLocation: ''
})
is of same type which is Observable of UserInfo but I am not able to fix this.
Please someone suggest the solution by noted down that I can't make any change in type of getSessionInfo methis as it is override method.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您返回的是
Subscription
,而不是返回Observable
。更新包括switchMap
的代码片段。You are returning a
Subscription
instead of returning anObservable
. Update the snippet includingswitchMap
.