[英]error TS2571: Object is of type 'unknown'
Auth-service.ts as you can see in sign in and sign up method I'm trying to store authenticated user data. Auth-service.ts正如您在登录和注册方法中看到的那样,我正在尝试存储经过身份验证的用户数据。 I'm getting an error ~~~(object is type of unknown)
我收到一个错误~~~(对象是未知类型)
signUp(email:any, password:any){
return this._http.post<AuthResponse>('https://identitytoolkit.googleapis.com/v1/accounts:signUp?key='+ config.API_KEY, {
email: email,
password: password,
returnSecureToken: true
}).pipe(
catchError(err =>{
return err;
}),tap(res => {
this.authenticatedUser(res.email, res.localId, res.idToken , +res.expiresIn)
})
)
}
signIn(email:any, password:any){
return this._http.post<AuthResponse>('https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key='+ config.API_KEY, {
email: email,
password: password,
returnSecureToken: true
}).pipe(
catchError(err =>{
return err;
}),tap(res =>{
this.authenticatedUser(res.email, res.localId, res.idToken , +res.expiresIn)
~~~ ~~~ ~~~ ~~~(object is type of unknown)
})
)
}
AuthResponse-interface as you can see I created an interface of response type... I'm using firebase api如您所见, AuthResponse-interface我创建了一个响应类型的接口...我正在使用 firebase api
export interface AuthResponse {
idToken: string,
email: string,
refreshToken: string,
expiresIn: string,
localId: string,
registered? : string
}
You don't seem to be defining the type of the parameter in tap
operator.您似乎没有在
tap
运算符中定义参数的类型。
signIn(email:any, password:any){
return this._http.post<AuthResponse>('https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key='+ config.API_KEY, {
email: email,
password: password,
returnSecureToken: true
}).pipe(
catchError(err =>{
return err;
}),
tap((res: AuthResponse) => { // <-- define type here
this.authenticatedUser(res.email, res.localId, res.idToken , +res.expiresIn)
})
);
}
Or you could also use bracket notation instead of dot notation.或者您也可以使用括号表示法而不是点表示法。
signIn(email:any, password:any){
return this._http.post<AuthResponse>('https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key='+ config.API_KEY, {
email: email,
password: password,
returnSecureToken: true
}).pipe(
catchError(err =>{
return err;
}),
tap((res: any) => {
this.authenticatedUser(res['email'], res['localId'], res['idToken'], +res['expiresIn'])
})
);
}
But since you have already defined the type I'd advise to use it instead of any
.但是由于您已经定义了类型,我建议您使用它而不是
any
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.