做这样的事情被认为是不好的做法吗?
我最初说的是observable类型为UserCreationResponse,但是随后使用map返回一个User
。这对于我的用例很方便,因为json响应会自动映射到UserCreationResponse,然后在我订阅可观察对象时得到用户。但是我想知道这是否会误导某些人阅读代码?
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;
}));