0

Working on an Angular 1 application, and trying to extend my promises with an 'abort' function. When I try to add abort to deferred.promise I get an abort does not exist on type IPromise<{}> error, obviously.'

How do I tell the property of this object to be a new class inline so that I can do this?

  deferred.promise.abort = function() {
     deferred.resolve();
  };

1 Answer 1

1

It can be

interface IAbortablePromise<T> extends ng.IPromise<T> {
    abort: () => void;
}

(deferred.promise as IAbortablePromise<any>).abort = function() { ... };

Or better,

interface IAbortableDeferred<T> extends ng.IDeferred<T> {
    promise: IAbortablePromise<T>;
}

const deferred = <IAbortableDeferred<any>>$q.defer();
deferred.promise.abort = function() { ... };
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.