Skip to content

Commit

Permalink
Merge 056a003 into bb38636
Browse files Browse the repository at this point in the history
  • Loading branch information
SalathielGenese committed May 17, 2019
2 parents bb38636 + 056a003 commit e33213c
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
18 changes: 18 additions & 0 deletions asyncResult.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export default class AsyncResult<V, E = Error>
{
static fail<E>( err: E ): AsyncResult<never, E>;
static success<V>( data ): AsyncResult<V, never>;

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;
}
4 changes: 4 additions & 0 deletions config.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import AsyncResult from './asyncResult';

export default config;
declare const config: { AsyncResult: AsyncResult<any> };
3 changes: 3 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { toAsyncResult, wrapMethod, addAsync } from './utils';
export { default as AsyncResult } from './asyncResult';
export { default as config } from './config';
36 changes: 36 additions & 0 deletions utils.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import AsyncResult from './asyncResult';



export const toAsyncResult: {
<E extends Error>(
error: E,
OwnAsyncResult?: typeof AsyncResult,
): Promise<AsyncResult<never, E>>;
<V, E>(
asyncResult: AsyncResult<V, E>,
OwnAsyncResult?: typeof AsyncResult,
): Promise<AsyncResult<V, E>>;
<V>(
value: V,
OwnAsyncResult?: typeof AsyncResult,
): Promise<AsyncResult<V, null>>;
};

export const wrapMethod: {
<T, P extends any[], R>(
method: (this: T, ...parameters: P ) => Promise<R> | R,
options?: {
context?: T,
AsyncResult?: typeof AsyncResult,
}
): AsyncResult<R>;
};

export const addAsync: {
<T, K extends keyof T>(
context: T,
methodName: K | K[],
options?: { context?: null|T }
): void;
};

0 comments on commit e33213c

Please sign in to comment.