के साथ एक कोणीय जेएस $ क्यू वादा लौटा रहा है मेरे पास एक ऐसी सेवा है जो एक स्थगित ऑब्जेक्ट को लौटने वाले मेरे कार्यों के साथ $ http लपेटती है।टाइपस्क्रिप्ट
मेरे इंटरफ़ेस:
export interface MyServiceScope {
get: ng.IPromise<{}>;
}
मेरी कक्षा:
export class MyService implements MyServiceScope {
static $inject = ['$http', '$log'];
constructor(private $http: ng.IHttpService,
private $log: ng.ILogService,
private $q: ng.IQService) {
this.$http = $http;
this.$log = $log;
this.$q = $q;
}
get(): ng.IPromise<{}> {
var self = this;
var deferred = this.$q.defer();
this.$http.get('http://localhost:8000/tags').then(
function(response) {
deferred.resolve(response.data);
},
function(errors) {
self.$log.debug(errors);
deferred.reject(errors.data);
}
);
return deferred.promise;
}
}
संकलन निम्न त्रुटि के साथ विफल हो रहा है:
myservice.ts(10,18): error TS2420: Class 'MyService' incorrectly implements interface 'MyServiceScope'.
Types of property 'get' are incompatible.
Type '() => IPromise<{}>' is not assignable to type 'IPromise<{}>'.
Property 'then' is missing in type '() => IPromise<{}>'.
संदर्भ के लिए, DefinitelyTyped से here is the IPromise परिभाषा। IQService.defer()
कॉल IDeferred
ऑब्जेक्ट देता है, और फिर deferred.promise
आईप्रोमाइज़ ऑब्जेक्ट देता है।
मुझे यकीन नहीं है कि क्या मैं अपने इंटरफ़ेस में गलत परिभाषाओं का उपयोग कर रहा हूं, या स्थगित ऑब्जेक्ट को उसी तरह वापस नहीं कर रहा हूं। कोई भी इनपुट बहुत प्रंशसनीय होगा!
आप सभी को यह छोड़ सकते हैं। =; लाइनें –