當我調用下面的方法,我想趕上錯誤,並檢查錯誤代碼,我不能指定錯誤類型以外的錯誤類型,所以我無法訪問該錯誤。代碼來自firebase.auth.Error
。createUserWithEmailAndPassword和處理捕獲與firebase.auth.Error給編譯錯誤TS2345
了Methode描述: (方法)firebase.auth.Auth.createUserWithEmailAndPassword(電子郵件:字符串,密碼:字符串):firebase.Promise
Specifing 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' –