From 7d013afce9fbf3103b4c98aabeae0ac9429e4dfc Mon Sep 17 00:00:00 2001 From: SalathielGenese Date: Fri, 17 May 2019 04:05:38 +0100 Subject: [PATCH 1/6] Type definition for AsyncResult class --- asyncResult.d.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 asyncResult.d.ts diff --git a/asyncResult.d.ts b/asyncResult.d.ts new file mode 100644 index 0000000..a63ab6d --- /dev/null +++ b/asyncResult.d.ts @@ -0,0 +1,15 @@ +export default class AsyncResult +{ + static fail( err: E ): AsyncResult; + static success( data ): AsyncResult; + + public constructor( err?: E, val?: V ); + + hasValue(): boolean; + isError(): boolean; + isOk(): boolean; + + errOrVal(): E | V | undefined; + err(): E | undefined; + val(): V | undefined; +} From 553e5e89910a18b3ec4545e3b24665f0a5b91e3e Mon Sep 17 00:00:00 2001 From: SalathielGenese Date: Fri, 17 May 2019 05:02:33 +0100 Subject: [PATCH 2/6] Type definition for config --- config.d.ts | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 config.d.ts diff --git a/config.d.ts b/config.d.ts new file mode 100644 index 0000000..c1f7625 --- /dev/null +++ b/config.d.ts @@ -0,0 +1,4 @@ +import AsyncResult from './asyncResult'; + +export default config; +declare const config: { AsyncResult: AsyncResult }; From 3849160d152ae578492716f9aa86bca71942f787 Mon Sep 17 00:00:00 2001 From: SalathielGenese Date: Fri, 17 May 2019 05:02:54 +0100 Subject: [PATCH 3/6] Type definition for toAsyncResult, wrapMethod and addAsync --- utils.d.ts | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 utils.d.ts diff --git a/utils.d.ts b/utils.d.ts new file mode 100644 index 0000000..78f7d61 --- /dev/null +++ b/utils.d.ts @@ -0,0 +1,36 @@ +import AsyncResult from './asyncResult'; + + + +export const toAsyncResult: { + ( + error: E, + OwnAsyncResult?: typeof AsyncResult, + ): Promise>; + ( + asyncResult: AsyncResult, + OwnAsyncResult?: typeof AsyncResult, + ): Promise>; + ( + value: V, + OwnAsyncResult?: typeof AsyncResult, + ): Promise>; +}; + +export const wrapMethod: { + ( + method: (this: T, ...parameters: P ) => Promise | R, + options?: { + context?: T, + AsyncResult?: typeof AsyncResult, + } + ): AsyncResult; +}; + +export const addAsync: { + ( + context: T, + methodName: K | K[], + options?: { context?: T } + ): void; +}; From 26ba0a0c744754821cef5fce0185b1a5e96162d7 Mon Sep 17 00:00:00 2001 From: SalathielGenese Date: Fri, 17 May 2019 05:04:28 +0100 Subject: [PATCH 4/6] Type definition for entry file --- index.d.ts | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 index.d.ts diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..13fd0c7 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,3 @@ +export { toAsyncResult, wrapMethod, addAsync } from './utils'; +export { default as AsyncResult } from './asyncResult'; +export { default as config } from './config'; From 7b4a3731ddf4dc17196f9f48441714463aa634da Mon Sep 17 00:00:00 2001 From: SalathielGenese Date: Fri, 17 May 2019 06:44:05 +0100 Subject: [PATCH 5/6] FIX support null as option context --- utils.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils.d.ts b/utils.d.ts index 78f7d61..98c0f86 100644 --- a/utils.d.ts +++ b/utils.d.ts @@ -31,6 +31,6 @@ export const addAsync: { ( context: T, methodName: K | K[], - options?: { context?: T } + options?: { context?: null|T } ): void; }; From 056a00395ca3dcd3ae432e0386c34e103b443a0f Mon Sep 17 00:00:00 2001 From: SalathielGenese Date: Fri, 17 May 2019 07:12:47 +0100 Subject: [PATCH 6/6] Expose setValue and setError --- asyncResult.d.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/asyncResult.d.ts b/asyncResult.d.ts index a63ab6d..effa028 100644 --- a/asyncResult.d.ts +++ b/asyncResult.d.ts @@ -12,4 +12,7 @@ export default class AsyncResult errOrVal(): E | V | undefined; err(): E | undefined; val(): V | undefined; + + setValue( value: V ): void; + setError( error: E ): void; }