How can I implement $ http in Typescript?

I'm having trouble defining my $ http call in Typescript. I used to use .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 have changed the usage. 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 assigned to type 'ITopic []'. The length of the 'length' property is not in the type '{}'. admin C: \ H \ admin \ admin \ app \ services \ themeservice.ts 214 Severity Code Description TS2322 project file line error Type '{}' is not assigned to type 'ITopic []. admin C: \ H \ admin \ admin \ app \ services \ themeservice.ts 215

Errors occur in the lines where I assign angular.copy (data) for self.topics and self.topicsBase

+4
1

'(data: IHttpPromiseCallbackArg<{}>, status: any, headers: any, config: any) => any' '(response: IHttpPromiseCallbackArg<{}>) => any'

, , , $http().

:

$http({
    method: "GET",
    url: myURL
})
    .then((response): any => { },(): any => {});
+3

Source: https://habr.com/ru/post/1608400/


All Articles