Versions
- angular 1.6.4
- typescript 2.3.2
- ui-router 1.0.3
- Hopefully not relevant(because I don't like dealing with webpack issues), but bundled with webpack 2.5.1 and ts-loader 2.0.3.
Issue
This is a question rather than a declarative issue on ui-router's github because I'm not very sure about the root cause analysis or the proper fix. I'm also not sure if this is an issue in our typescript environment or not.
I'm following https://ui-router.github.io/guide/ng1/migrate-to-1_0 to migrate our existing app (which is hybrid js/typescript) to ui-router 1.0.3. Specifically having trouble with:
// Migrate to: UI-Router 1.0 Transition Hook
app.run(function($transitions) {
$transitions.onStart({ }, function(trans) {
var SpinnerService = trans.injector().get('SpinnerService');
SpinnerService.transitionStart();
trans.promise.finally(SpinnerService.transitionEnd);
});
})
I get the following error referencing the line with finally:
error TS2339: Property 'finally' does not exist on type 'Promise'.
My exact code looks like:
import router = require("@uirouter/angularjs");
// <snip a bunch of boilerplate>
constructor($scope: angular.IScope, $transitions: router.TransitionService) {
this.loading = true;
$transitions.onStart({}, (trans: router.Transition) => {
this.setLoading(true)();
trans.promise.finally(this.setLoading(false));
});
}
We have a simple tsconfig that looks like:
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"target": "es5",
"sourceMap": true,
"module": "commonjs"
},
"exclude": [
"node_modules"
]
}
When I was trying to find the root cause I found that ui-router's declaration file sets the type of .promise to Promise. My IDE (emacs with tide) doesn't know where this Promise comes from but I'm guessing it is the es6 Promise interface(mozilla doc), which doesn't include finally.
However, by expectations (and the guide above) I assume they actually use ng.IPromise(angular.js's promise implementation, details found at $q service).
If (a BIG if) my understanding is correct this means that this is a bug in their type declarations where they should be defining their promise types as a different class/type.
If it is I'll file a bug but will be interested in the correct way to make a local workaround because I'm not sure how I should do it.
Is this the case or is something else the root cause of my issues?