1
我正在使用Javascript/Typescript創建返回的Promise
和已格式化的PersonModel
對象。但是我得到生成錯誤:Javascript Promise calling promise confusion
PersonService.ts
private encryptPerson(person: PersonModel): Promise<PersonModel> {
return new Promise<PersonModel>(resolve => { // <== line 332
let password: string = person.password;
this.encrypt(password).then((ciphertext: string) => {
person.password = ciphertext;
resolve(person);
});
},
error => {
console.error(error)
});
}
private encrypt(value: string): Promise<string> {
return new Promise<string>(resolve => {
this.encrypter.encrypt(value).then((result) => {
resolve(result);
},
error => {
console.error(error)
});
});
}
錯誤
ERROR in ./app/pages/service/personService.ts (332,16): error TS2346: Supplied parameters do not match any signature of call target.
的我應該如何構建這種讚賞任何幫助。
UPDATE
從T.J.提醒後下面克勞德,我有以下幾點:
private encryptPerson(person: PersonModel): Promise<PersonModel> {
return new Promise<PersonModel>(resolve => {
let password: string = person.password;
this.encrypt(password).then((ciphertext: string) => {
person.password = ciphertext;
resolve(person);
});
});
}
private encrypt(value: string): Promise<string> {
return new Promise<string>(resolve => {
this.encrypter.encrypt(value).then((result: string) => {
resolve(result);
});
});
}
您正在調用傳遞給調用目標的參數。指定在 – Justinas
上發生此錯誤的行@Justinas:它有點隱藏,但他們已經在代碼註釋中指出哪一行是第332行。 –
@Justina,請參閱以下內容:'// <== line 332' – Richard