diff --git a/asyncResult.d.ts b/asyncResult.d.ts new file mode 100644 index 0000000..effa028 --- /dev/null +++ b/asyncResult.d.ts @@ -0,0 +1,18 @@ +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; + + setValue( value: V ): void; + setError( error: E ): void; +} 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 }; 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'; diff --git a/utils.d.ts b/utils.d.ts new file mode 100644 index 0000000..98c0f86 --- /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?: null|T } + ): void; +};