I recently developed a Typescript service:
class SettingsService implements ISettingsService {
public info = {};
public backupInfo = {};
public userConfig = {};
public isLoaded = false;
constructor(
private $http: ng.IHttpService,
private $q: ng.IQService
) {
}
static $inject = [
'$http',
'$q'
];
save = ():ng.IHttpPromise<> => {
var defer = this.$q.defer();
if (angular.equals(this.info, this.backupInfo)) {
return defer.resolve();
} else {
this.$http({
data: {
infoJSON: JSON.stringify(this.info),
userConfigJSON: JSON.stringify(this.userConfig)
},
url: '/api/Settings/Save',
method: "POST"
})
.then(function (data) {
this.backupInfo = angular.copy(this.info);
this.userConfigBackup = angular.copy(this.userConfig)
return defer.resolve();
});
}
return defer.promise;
};
}
In addition to the service, I defined an interface as well:
interface ISettingsService {
save(): ng.IHttpPromise<>;
}
Unexpectedly, there's an error occurring in the code:
Error 3 Cannot convert 'void' to 'ng.IHttpPromise<any>'.
Error 4 Cannot convert 'ng.IPromise<{}>' to 'ng.IHttpPromise<any>':
Type 'ng.IPromise<{}>' does not have the property 'success' as expected in type 'ng.IHttpPromise<any>'.