UNPKG

3.54 kBTypeScriptView Raw
1/** An enum for Transition Rejection reasons */
2declare enum RejectType {
3 /**
4 * A new transition superseded this one.
5 *
6 * While this transition was running, a new transition started.
7 * This transition is cancelled because it was superseded by new transition.
8 */
9 SUPERSEDED = 2,
10 /**
11 * The transition was aborted
12 *
13 * The transition was aborted by a hook which returned `false`
14 */
15 ABORTED = 3,
16 /**
17 * The transition was invalid
18 *
19 * The transition was never started because it was invalid
20 */
21 INVALID = 4,
22 /**
23 * The transition was ignored
24 *
25 * The transition was ignored because it would have no effect.
26 *
27 * Either:
28 *
29 * - The transition is targeting the current state and parameter values
30 * - The transition is targeting the same state and parameter values as the currently running transition.
31 */
32 IGNORED = 5,
33 /**
34 * The transition errored.
35 *
36 * This generally means a hook threw an error or returned a rejected promise
37 */
38 ERROR = 6
39}
40export { RejectType };
41export declare class Rejection {
42 /** @internal */
43 $id: number;
44 /**
45 * The type of the rejection.
46 *
47 * This value is an number representing the type of transition rejection.
48 * If using Typescript, this is a Typescript enum.
49 *
50 * - [[RejectType.SUPERSEDED]] (`2`)
51 * - [[RejectType.ABORTED]] (`3`)
52 * - [[RejectType.INVALID]] (`4`)
53 * - [[RejectType.IGNORED]] (`5`)
54 * - [[RejectType.ERROR]] (`6`)
55 *
56 */
57 type: RejectType;
58 /**
59 * A message describing the rejection
60 */
61 message: string;
62 /**
63 * A detail object
64 *
65 * This value varies based on the mechanism for rejecting the transition.
66 * For example, if an error was thrown from a hook, the `detail` will be the `Error` object.
67 * If a hook returned a rejected promise, the `detail` will be the rejected value.
68 */
69 detail: any;
70 /**
71 * Indicates if the transition was redirected.
72 *
73 * When a transition is redirected, the rejection [[type]] will be [[RejectType.SUPERSEDED]] and this flag will be true.
74 */
75 redirected: boolean;
76 /** Returns true if the obj is a rejected promise created from the `asPromise` factory */
77 static isRejectionPromise(obj: any): boolean;
78 /** Returns a Rejection due to transition superseded */
79 static superseded(detail?: any, options?: any): Rejection;
80 /** Returns a Rejection due to redirected transition */
81 static redirected(detail?: any): Rejection;
82 /** Returns a Rejection due to invalid transition */
83 static invalid(detail?: any): Rejection;
84 /** Returns a Rejection due to ignored transition */
85 static ignored(detail?: any): Rejection;
86 /** Returns a Rejection due to aborted transition */
87 static aborted(detail?: any): Rejection;
88 /** Returns a Rejection due to aborted transition */
89 static errored(detail?: any): Rejection;
90 /**
91 * Returns a Rejection
92 *
93 * Normalizes a value as a Rejection.
94 * If the value is already a Rejection, returns it.
95 * Otherwise, wraps and returns the value as a Rejection (Rejection type: ERROR).
96 *
97 * @returns `detail` if it is already a `Rejection`, else returns an ERROR Rejection.
98 */
99 static normalize(detail?: Rejection | Error | any): Rejection;
100 constructor(type: number, message?: string, detail?: any);
101 toString(): string;
102 toPromise(): Promise<any>;
103}