Я работаю над улучшением своего компонента Login с использованием некоторых сгенерированных JHipster сервисов, но я столкнулся с проблемой.
Я получаю error TS2339: Property 'finally' does not exist on type 'Promise<void>'.
, когда пытаюсь отправить форму входа.
Вот код, который генерирует ошибку: login.component.ts
login() {
if (this.validate(this.form)) {
this.loginService
.login({
username: this.model.username,
password: this.model.password,
})
.then(() => {
this.redirectUser();
})
.catch(() => {
this.authNoticeService.setNotice('The username or password is incorrect', 'error');
})
.finally(() => {
this.spinner.active = false;
this.actionChange.next( this.action );
});
}
}
login.service.ts
login(credentials, callback?) {
const cb = callback || function() {};
return new Promise((resolve, reject) => {
this.authServerProvider.login(credentials).subscribe(
data => {
this.principal.identity(true).then(account => {
// After the login the language will be changed to
// the language selected by the user during his registration
if (account !== null) {
this.languageService.changeLanguage(account.langKey);
}
resolve(data);
});
return cb();
},
err => {
this.logout();
reject(err);
return cb(err);
}
);
});
}
Я пытался добавить возвращаемый тип метода входа из login.service.ts
, например:
login(credentials, callback?):Promise<any> {
Но безуспешно.
Я провел некоторое исследование и в соответствии с этим: https://stackoverflow.com/a/52098456/9026582 проблема должна быть решена с помощью typescript: 2.7.0
.
У меня есть typescript: 2.7.2
версия, поэтому я думаю, что это не так.
Может быть, проблема связана с обратными вызовами в методе login(credentials, callback?)
?
РЕДАКТИРОВАТЬ: оригинальная конфигурация tsconfig.json
tsconfig.json
{
"compileOnSave": false,
"compilerOptions": {
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"target": "es5",
"typeRoots": [
"./node_modules/@types"
],
"lib": [
"es2017",
"dom"
]
}
}
tsconfig.app.json
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/app",
"baseUrl": "./",
"module": "es2015",
"types": []
},
"exclude": [
"test.ts",
"**/*.spec.ts"
]
}