-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Description
I'm currently developing in TS 1.7, compiling to ES6, and transpiling with Babel to ES5. I use Angular 1.x for my frontend development currently.
I am able to leverage async functions by returning a custom type, QPromise
, for which I've written a definition like this:
declare class QPromise<T> implements angular.IPromise<T> {
constructor(resolver: (resolve: angular.IQResolveReject<T>, reject: angular.IQResolveReject<any>) => any);
then<TResult>(successCallback: (promiseValue: T) => angular.IPromise<TResult>|TResult, errorCallback?: (reason: any) => any, notifyCallback?: (state: any) => any): angular.IPromise<TResult>;
catch<TResult>(onRejected: (reason: any) => angular.IPromise<TResult>|TResult): angular.IPromise<TResult>;
finally(finallyCallback: () => any): angular.IPromise<T>;
}
I then create a JavaScript file with a definition QPromise:
function QPromise(resolver) {
var $q = angular.injector(['ng']).get("$q");
return new $q(resolver);
};
While less than elegant, this has been an acceptable shim for now so that I can use async while still using Angular's $q library, which is needed to get Angular digest to occur automatically.
TS 1.8 no longer lets me return a QPromise<T>
, complaining: error TS1064: The return type of an async function or method must be the global Promise<T> type.
This all but breaks my ability to work with Angular 1 and still use TS async functions.