forked from jeffbski/redux-logic
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.d.ts
More file actions
73 lines (62 loc) · 2.4 KB
/
action.d.ts
File metadata and controls
73 lines (62 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
* *** MIT LICENSE ***
* -------------------------------------------------------------------------
* This code may be modified and distributed under the MIT license.
* See the LICENSE file for details.
* -------------------------------------------------------------------------
*
* @summary Definitions for redux-logic
*
* @author Alvis HT Tang <alvis@hilbert.space>
* @license MIT
* @copyright Copyright (c) 2018 - All Rights Reserved.
* -------------------------------------------------------------------------
*/
//
// ACTION
//
/* * * * * *
| The following definitions are bascially identical to |
| flux-standard-action without an extra package. It also |
| makes use of conditional type to make the type of |
| payload and meta more accurate. |
* * * * * */
/** Action as an agrument */
export type ArgumentAction<
Type extends string = string,
Payload extends object = undefined,
Meta extends object = undefined
> = ActionBasis<Type> & Partial<Action<string, object, object>>;
/** all different types of Action */
export type Action<
Type extends string = string,
Payload extends object = undefined,
Meta extends object = undefined
> =
| ErroneousAction<Type, Meta>
| (StandardAction<Type, Payload, Meta> & { error?: false });
/** Action without any error */
export type StandardAction<
Type extends string = string,
Payload extends object = undefined,
Meta extends object = undefined
> = ActionBasis<Type> & PayloadBasis<Payload> & MetaBasis<Meta>;
/** Action with an Error */
export type ErroneousAction<
Type extends string = string,
Meta extends object = undefined
> = ActionBasis<Type> & PayloadBasis<Error> & MetaBasis<Meta> & { error: true };
/* ----- Auxiliary Types ----- */
/** the most basic action object */
export interface ActionBasis<Type extends string = string> {
type: Type extends infer U ? U : string;
}
/** return an interface with payload only if it presents */
export type PayloadBasis<
Payload extends object = undefined
> = Payload extends undefined ? {} : { payload: Payload };
/** return an interface with meta only if it presents */
export type MetaBasis<Meta extends object = undefined> = Meta extends undefined
? {}
: { meta: Meta };
// ---------------------------------------- //