-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
types.ts
147 lines (123 loc) · 3.09 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
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
import type { ComputedRef, Ref, WatchOptions, WatchSource } from 'vue-demi'
/**
* Void function
*/
export type Fn = () => void
/**
* Any function
*/
export type AnyFn = (...args: any[]) => any
/**
* A ref that allow to set null or undefined
*/
export type RemovableRef<T> = Omit<Ref<T>, 'value'> & {
get value(): T
set value(value: T | null | undefined)
}
/**
* @deprecated Use `RemovableRef`
*/
export type RemoveableRef<T> = RemovableRef<T>
/**
* Maybe it's a ref, or a plain value
*
* ```ts
* type MaybeRef<T> = T | Ref<T>
* ```
*/
export type MaybeRef<T> = T | Ref<T>
/**
* Maybe it's a ref, or a plain value, or a getter function
*
* ```ts
* type MaybeComputedRef<T> = (() => T) | T | Ref<T> | ComputedRef<T>
* ```
*/
export type MaybeComputedRef<T> = MaybeReadonlyRef<T> | MaybeRef<T>
/**
* Maybe it's a computed ref, or a getter function
*
* ```ts
* type MaybeReadonlyRef<T> = (() => T) | ComputedRef<T>
* ```
*/
export type MaybeReadonlyRef<T> = (() => T) | ComputedRef<T>
/**
* Make all the nested attributes of an object or array to MaybeRef<T>
*
* Good for accepting options that will be wrapped with `reactive` or `ref`
*
* ```ts
* UnwrapRef<DeepMaybeRef<T>> === T
* ```
*/
export type DeepMaybeRef<T> = T extends Ref<infer V>
? MaybeRef<V>
: T extends Array<any> | object
? { [K in keyof T]: DeepMaybeRef<T[K]> }
: MaybeRef<T>
export type Arrayable<T> = T[] | T
/**
* Infers the element type of an array
*/
export type ElementOf<T> = T extends (infer E)[] ? E : never
export type ShallowUnwrapRef<T> = T extends Ref<infer P> ? P : T
export type Awaitable<T> = Promise<T> | T
export type ArgumentsType<T> = T extends (...args: infer U) => any ? U : never
export type PromisifyFn<T extends AnyFn> = (...args: ArgumentsType<T>) => Promise<ReturnType<T>>
export interface Pausable {
/**
* A ref indicate whether a pausable instance is active
*/
isActive: Readonly<Ref<boolean>>
/**
* Temporary pause the effect from executing
*/
pause: Fn
/**
* Resume the effects
*/
resume: Fn
}
export interface Stoppable<StartFnArgs extends any[] = any[]> {
/**
* A ref indicate whether a stoppable instance is executing
*/
isPending: Readonly<Ref<boolean>>
/**
* Stop the effect from executing
*/
stop: Fn
/**
* Start the effects
*/
start: (...args: StartFnArgs) => void
}
/**
* @deprecated Use `Stoppable`
*/
export type Stopable = Stoppable
export interface ConfigurableFlush {
/**
* Timing for monitoring changes, refer to WatchOptions for more details
*
* @default 'pre'
*/
flush?: WatchOptions['flush']
}
export interface ConfigurableFlushSync {
/**
* Timing for monitoring changes, refer to WatchOptions for more details.
* Unlike `watch()`, the default is set to `sync`
*
* @default 'sync'
*/
flush?: WatchOptions['flush']
}
// Internal Types
export type MapSources<T> = {
[K in keyof T]: T[K] extends WatchSource<infer V> ? V : never;
}
export type MapOldSources<T, Immediate> = {
[K in keyof T]: T[K] extends WatchSource<infer V> ? Immediate extends true ? V | undefined : V : never;
}