Skip to content

Commit

Permalink
fix: open promise legacy typescript fix
Browse files Browse the repository at this point in the history
  • Loading branch information
alisahinozcelik committed Nov 22, 2020
1 parent 832b378 commit 51fdd4c
Showing 1 changed file with 25 additions and 30 deletions.
55 changes: 25 additions & 30 deletions src/open-promise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,21 @@ export class OpenPromise<T = any> extends Promise<T> {
*/
public reject: Rejector;

/**
* Returns whether is the promise resolved
*/
public resolved: boolean;

/**
* Returns whether is the promise rejected
*/
public rejected: boolean;

/**
* Returns whether is the promise finished
*/
public finished: boolean;

/**
* Open Promise Constructor
*/
Expand Down Expand Up @@ -96,36 +111,6 @@ export class OpenPromise<T = any> extends Promise<T> {
this.reject = rejector;
}

/**
* Returns whether is the promise resolved
*/
public get resolved(): boolean {
return this[RESOLVED];
}
public set resolved(value) {
throw new Error('Property `resolved` can not been set');
}

/**
* Returns whether is the promise rejected
*/
public get rejected(): boolean {
return this[REJECTED];
}
public set rejected(value) {
throw new Error('Property `rejected` can not been set');
}

/**
* Returns whether is the promise finished
*/
public get finished(): boolean {
return this[RESOLVED] || this[REJECTED];
}
public set finished(value) {
throw new Error('Property `finished` can not been set');
}

/**
* Binds a promise to the inner promise to resolve or reject with it
* @param promise A promise to bind inner promise
Expand All @@ -138,3 +123,13 @@ export class OpenPromise<T = any> extends Promise<T> {
}
}
}

Object.defineProperty(OpenPromise.prototype, 'resolved', {get() {
return this[RESOLVED];
}});
Object.defineProperty(OpenPromise.prototype, 'rejected', {get() {
return this[REJECTED];
}});
Object.defineProperty(OpenPromise.prototype, 'finished', {get() {
return this[RESOLVED] || this[REJECTED];
}});

0 comments on commit 51fdd4c

Please sign in to comment.