I am having problems defining my $http call in Typescript. Previously I was using .success and .error like this:
this.$http({
method: "GET",
url: self.ac.dataServer + url
})
.success((data: any, status: number, headers: (headerName: string) => string, config: ng.IRequestConfig): void => {
self.topics = angular.copy(data);
self.topicsBase = angular.copy(data);
this.$state.transitionTo('home.subjects.subject.admin.topics', {
subjectId: this.sus.subject.id
});
})
.error((data, status, headers, config): void => {
self.topics = null;
self.topicsBase = null;
})
.finally((): void => {
});
Now I changed to use .then:
this.$http({
method: "GET",
url: self.ac.dataServer + url
})
.then(
(response): any => {
self.topics = angular.copy(response.data);
self.topicsBase = angular.copy(response.data);
this.$state.transitionTo('home.subjects.subject.admin.topics', {
subjectId: this.sus.subject.id
});},
(response): any => {
self.topics = null;
self.topicsBase = null;
}
);
But this gives me the following errors:
Severity Code Description Project File Line Error TS2322 Type '{}' is not assignable to type 'ITopic[]'. Property 'length' is missing in type '{}'. admin C:\H\admin\admin\app\services\topicservice.ts 214 Severity Code Description Project File Line Error TS2322 Type '{}' is not assignable to type 'ITopic[]'. admin C:\H\admin\admin\app\services\topicservice.ts 215
The errors come up on the lines where I am assigning an angular.copy(data) to self.topics and self.topicsBase