typescript - 可观察回报与一般差异
问题描述
这样做是否被认为是不好的做法?
我最初说 observable 是 UserCreationResponse 类型,但随后使用 map 返回一个User
. 这对我的用例来说很方便,因为 json 响应会自动映射到 UserCreationResponse,然后当我订阅 observable 时,我会得到用户。但我想知道它是否会误导阅读代码的人?
signup(email : string, password : string) {
return this.http.post<UserCreationResponse>("https://www.googleapis.com/identitytoolkit/v3/relyingparty/signupNewUser?key="+this.apiKey, {
email: email,
password : password,
returnSecureToken : true
}).pipe(catchError(error => {return throwError("pipedErrror"+error.toString())}),
map(resData => {
const expirationDate = new Date(new Date().getTime() + +resData.expiresIn * 1000);
const user = new User(
resData.email, +resData.localId, resData.idToken, expirationDate
)
this.user.next(user);
return user;
}));
解决方案
推荐阅读
- python - 无法将 html 转换为 JSON
- python - 如何在打开具有 HTML 标签的文本文件时使用替换命令?
- swift - 如何在 Swift 中的 Structure 中声明特定协议?
- yarnpkg - Yarn 默认使用 .yarn/releases/yarn 吗?
- php - 我正在尝试使用嵌套循环来获取子类别,但我以错误结尾“此集合实例上不存在属性 [类别]”
- webrtc - webrtc 移动客户端连接到不同网络时没有音频
- c# - ASP NET 如何在某些条件下显示部分页面?
- php - Laravel 中的 Ldap 绑定消息
- javascript - SOCKET.IO - console.log 正在打印所需的输出,但不是 io.emit
- c - ebpf bpf_get_socket_uid 错误:insn[0].code 0x85 的 relo 无效