-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.ts
42 lines (35 loc) · 1.25 KB
/
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
export interface Obj {
[key: string]: any
}
export type Reducer<TState, Action> = (
state: TState,
action: Action
) => any | void
type OmitFirstParam<T = any[]> = T extends [any, ...infer Rest] ? Rest : never
export type State<TState> = {
[Prop in keyof TState]: TState[Prop] extends (...args: any[]) => any
? (...args: OmitFirstParam<Parameters<TState[Prop]>>) => TState[Prop]
: TState[Prop]
}
export type CreateHook<TState> = (() => State<TState>) & {
subscribe: (cb: () => void | any) => () => boolean
state: State<TState>
}
export type ReduceHook<TState, Action> = (() => State<
TState & { dispatch: (_: TState, action: Action) => void }
>) & {
subscribe: (cb: () => void | any) => () => boolean
state: State<TState & { dispatch: (_: TState, action: Action) => void }>
}
export type AssignInternal<T, TState, Action> = T extends undefined
? { _status: boolean }
: { dispatch: (_: TState, action: Action) => void; _status: boolean }
export type PersistHook<TState, Action, ArgB> = (() => State<
Omit<TState, 'config'> & AssignInternal<ArgB, TState, Action>
>) & {
subscribe: (cb: () => void | any) => () => boolean
state: State<Omit<TState, 'config'> & AssignInternal<ArgB, TState, Action>>
persist: {
clearStorage: () => void
}
}