deno.land / x / xstate@xstate@4.33.6 / src / model.types.ts

model.types.ts
نووسراو ببینە
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import { AnyFunction, AssignAction, Assigner, BaseActionObject, Compute, EventObject, MachineConfig, Prop, PropertyAssigner, StateMachine, InternalMachineOptions, ServiceMap} from './types';import { ResolveTypegenMeta, TypegenConstraint, TypegenDisabled} from './typegenTypes';
// real `ExtractEvent` breaks `model.assign` inference within transition actionstype SimplisticExtractEvent< TEvent extends EventObject, TEventType extends TEvent['type']> = TEvent extends { type: TEventType } ? TEvent : never;
export interface Model< TContext, TEvent extends EventObject, TAction extends BaseActionObject = BaseActionObject, TModelCreators = void> { initialContext: TContext; assign: <TEventType extends TEvent['type'] = TEvent['type']>( assigner: | Assigner<TContext, SimplisticExtractEvent<TEvent, TEventType>> | PropertyAssigner<TContext, SimplisticExtractEvent<TEvent, TEventType>>, eventType?: TEventType ) => AssignAction<TContext, SimplisticExtractEvent<TEvent, TEventType>>; events: Prop<TModelCreators, 'events'>; actions: Prop<TModelCreators, 'actions'>; reset: () => AssignAction<TContext, any>; createMachine: { < TServiceMap extends ServiceMap = ServiceMap, TTypesMeta extends TypegenConstraint = TypegenDisabled >( config: MachineConfig< TContext, any, TEvent, TAction, TServiceMap, TTypesMeta >, implementations?: InternalMachineOptions< TContext, TEvent, ResolveTypegenMeta<TTypesMeta, TEvent, TAction, TServiceMap> > ): StateMachine< TContext, any, TEvent, { value: any; context: TContext }, TAction, TServiceMap, ResolveTypegenMeta<TTypesMeta, TEvent, TAction, TServiceMap> >; };}
export type ModelContextFrom< TModel extends Model<any, any, any, any>> = TModel extends Model<infer TContext, any, any, any> ? TContext : never;
export type ModelEventsFrom< TModel extends Model<any, any, any, any> | undefined> = TModel extends Model<any, infer TEvent, any, any> ? TEvent : EventObject;
export type ModelActionsFrom< TModel extends Model<any, any, any, any>> = TModel extends Model<any, any, infer TAction, any> ? TAction : never;
export type EventCreator< Self extends AnyFunction, Return = ReturnType<Self>> = Return extends object ? Return extends { type: any; } ? "An event creator can't return an object with a type property" : Self : 'An event creator must return an object';
export type EventCreators<Self> = { [K in keyof Self]: Self[K] extends AnyFunction ? EventCreator<Self[K]> : 'An event creator must be a function';};
export type FinalEventCreators<Self> = { [K in keyof Self]: Self[K] extends AnyFunction ? ( ...args: Parameters<Self[K]> ) => Compute<ReturnType<Self[K]> & { type: K }> : never;};
export type ActionCreator< Self extends AnyFunction, Return = ReturnType<Self>> = Return extends object ? Return extends { type: any; } ? "An action creator can't return an object with a type property" : Self : 'An action creator must return an object';
export type ActionCreators<Self> = { [K in keyof Self]: Self[K] extends AnyFunction ? ActionCreator<Self[K]> : 'An action creator must be a function';};
export type FinalActionCreators<Self> = { [K in keyof Self]: Self[K] extends AnyFunction ? ( ...args: Parameters<Self[K]> ) => Compute<ReturnType<Self[K]> & { type: K }> : never;};
export interface ModelCreators<Self> { events?: EventCreators<Prop<Self, 'events'>>; actions?: ActionCreators<Prop<Self, 'actions'>>;}
export interface FinalModelCreators<Self> { events: FinalEventCreators<Prop<Self, 'events'>>; actions: FinalActionCreators<Prop<Self, 'actions'>>;}
export type UnionFromCreatorsReturnTypes<TCreators> = { [K in keyof TCreators]: TCreators[K] extends AnyFunction ? ReturnType<TCreators[K]> : never;}[keyof TCreators];
xstate

Version Info

Tagged at
2 years ago