0

I have this method in angular js. I had to update success to then because of change in version but now I get the mentioned error. I am using typings 6.5.6 taken from nuget, and typescript version 2.6 according to the project properties in Visual Studio.

This is my method. The error is in the 'then' part. It doesn't like the data being type string.

I have looked at IHttpPromise incorrectly extends IPromise with TypeScript 2.5 But IHttpPromise and IHttpResponse are not available to me, so are my typings version the issue?

  EmailQuote(quoteRef: string, password: string,testAddress:string,putintTAM:boolean): ng.IPromise<string> {

        var defer = this.q.defer<string>();
        this.rootScope.loading = true;           

        this.http({
            url: "api/quoteEngine/emailQuote?quoteRef=" + quoteRef + "&password=" + password + "&testAddress=" + testAddress + "&putinTam=" + putintTAM,
            method: "POST"                
        })
            .then((data: string) => {
                this.rootScope.loading = false;
                defer.resolve(data);
            })
            .catch((reason: any) => {
                this.rootScope.loading = false;
                this.ShowError(reason.data.message);
                defer.reject(reason.data);
            });

        return defer.promise;
    }
georgeawg
  • 48,608
  • 13
  • 72
  • 95
  • This is a [deferred Anti-pattern](https://stackoverflow.com/questions/30750207/is-this-a-deferred-antipattern). Remove the anti-pattern before going any further. – georgeawg Apr 24 '19 at 11:51
  • Removing the deferred object doesn't remove the error though –  Apr 24 '19 at 12:02
  • Returning the http object returns a promise, yes. But then it just passes the problem to the caller of EmailQuote. I just want to return a string type from this, instead of type any. –  Apr 24 '19 at 12:16
  • I thought the point of typescript was to work with real types. That answer that is pasted here is saying just get a response.data, may as well be javascript. –  Apr 24 '19 at 12:22
  • I suppose you can just cast response.data? here it's just a string but for more complex objects it could be useful –  Apr 24 '19 at 12:41

0 Answers0