Reputation: 13
The following compiled and worked fine in Typescript 1.8 and Angular 1. Now our development platform is moving to Typescript 2.3. The same function fails to compile in Typescript 2.3 at the return statement:
"Type 'IPromise<{}>' is not assignable to type 'IPromise'"
How do you type a Promise? Is there a cast?
detail(id: string): ng.IPromise<IInvOrder> {
var defer = this.$q.defer();
this.$http.get(this.apiUrl + "/Detail/" + id)
.success((result: IInvOrder) => defer.resolve(result))
.error((err: any) => defer.reject(err));
return defer.promise;
}
Upvotes: 0
Views: 505
Reputation: 276293
TypeScript now forces you to use explicit generics when they cannot be inferred.
Change var defer = this.$q.defer();
to var defer = this.$q.defer<IInvOrder();
Upvotes: 3