In my class, I have a method that returns a chained promise. The first promise's type is angular.IPromise<Foo>
, and the second promise resolves with type angular.IPromise<Bar>
.
I am perplexed as to why the return type of doSomething
is angular.IPromise<Bar>
. Shouldn't it be angular.IPromise<Foo>
since that is what is initially returned by the function? Although I understand that the then()
function returns a promise and encapsulates its response, this concept still confuses me.
import { Something } from '../somewhere';
import { Bar } from '../somewhereelse';
class Test {
doSomething(): angular.IPromise<Bar> {
return Something.getFoo() // getFoo() return type angular.IPromise<Foo>
.then(() => {
let x: Bar = {};
return x;
});
}
}
I would greatly appreciate any assistance in clarifying this issue. I am willing to provide additional code if necessary.