【发布时间】:2017-04-01 07:13:21
【问题描述】:
当我调用以下方法并且我想捕获错误并检查错误代码时,我无法指定错误类型以外的错误类型,因此我无法访问错误。来自firebase.auth.Error的代码。
方法说明: (方法) firebase.auth.Auth.createUserWithEmailAndPassword(email: string, password: string): firebase.Promise
在 then 工作中指定 firebase.auth.Auth 但 firebase.auth.Error 给我一个编译错误。
error TS2345: Argument of type '(error: Error) => void' is not assignable to parameter of type '(a: Error) => any'.
Types of parameters 'error' and 'a' are incompatible.
Type 'Error' is not assignable to type 'firebase.auth.Error'.
Property 'code' is missing in type 'Error'.
this.auth.createUserWithEmailAndPassword(username, password)
.then( (auth: firebase.auth.Auth) => { return auth; } )
.catch( (error: firebase.auth.Error) => {
let errorCode = error.code;
let errorMessage = error.message;
if (errorMessage === "auth/weak-password") {
alert("The password is too weak.");
} else {
alert(errorMessage);
}
console.log(error);
});
【问题讨论】:
-
看起来你的
error变量是Error类型,你需要firebase.auth.Error
标签: typescript firebase firebase-authentication