Skip to content

Commit

Permalink
fix(IPromise): handle TS1055 error
Browse files Browse the repository at this point in the history
  • Loading branch information
oljekechoro authored and antongolub committed May 17, 2019
1 parent 3db37a3 commit 1619fb8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/facade/src/test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"target": "es6",
"target": "es5",
"module": "commonjs",
"strict": true,
"noImplicitAny": true,
Expand Down
23 changes: 14 additions & 9 deletions packages/types/src/main/IPromise.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import * as Bluebird from 'bluebird'

export type IPromise<T> = Bluebird<T> | Promise<T>

export type TPromiseExecutor<TValue = any, TReason = any> = (resolve: (value: TValue) => void, reject: (reason: TReason) => void) => void

export interface IPromiseConstructor<TValue = any, TReason = any> {
new(executor: TPromiseExecutor<TValue>): IPromise<TValue>
all: (values: Array<IPromise<TValue>>) => IPromise<TValue[]>
race: (values: Array<IPromise<TValue>>) => IPromise<TValue>
reject: (reason?: TReason) => IPromise<TValue>
resolve: (value?: TValue) => IPromise<TValue>
new(executor: TPromiseExecutor<TValue>): IPromise<TValue, TReason>
all: (values: Array<IPromise<TValue, TReason>>) => IPromise<TValue[], TReason>
race: (values: Array<IPromise<TValue, TReason>>) => IPromise<TValue, TReason>
reject: (reason?: TReason) => IPromise<TValue, TReason>
resolve: (value?: TValue) => IPromise<TValue, TReason>
}

export interface IPromise<TValue = any, TReason = any> {
then: (onSuccess?: (value: TValue) => any, onReject?: (reason: TReason) => any) => IPromise
catch: (onReject: (reason: TReason) => any) => IPromise
finally?: (onFinally: () => any) => IPromise
}

// https://stackoverflow.com/questions/45902881/ts1055-when-using-async-await-using-a-type-alias
export const IPromise = Promise
4 changes: 4 additions & 0 deletions packages/types/src/test/IPromise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ const nativePromiseConstructor: IPromiseConstructor = Promise;
const bluebirdPromiseConstructor: IPromiseConstructor = BluebirdPromise;
const nativePromise: IPromise<number> = new Promise<number>(executor);
const bluebirdPromise: IPromise<number> = new BluebirdPromise<number>(executor);

async function asyncFunction(): IPromise<number> {
return new Promise((resolve) => resolve(42));
}
2 changes: 1 addition & 1 deletion packages/types/src/test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"target": "es6",
"target": "es5",
"module": "commonjs",
"strict": true,
"noImplicitAny": true,
Expand Down

0 comments on commit 1619fb8

Please sign in to comment.