-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
types.ts
129 lines (110 loc) · 2.5 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
import type { Ref, WatchOptions, WatchSource } from 'vue-demi'
/**
* Any function
*/
export type Fn = () => void
/**
* 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 getter function
*
* ```ts
* type MaybeRef<T> = T | Ref<T>
* ```
*/
export type MaybeComputedRef<T> = T extends Function
? never
: (() => T) | MaybeRef<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>
/**
* 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 interface Pausable {
/**
* A ref indicate whether a pusable instance is active
*/
isActive: Ref<boolean>
/**
* Temporary pause the effect from executing
*/
pause: Fn
/**
* Resume the effects
*/
resume: Fn
}
export interface Stoppable {
/**
* A ref indicate whether a stoppable instance is executing
*/
isPending: Ref<boolean>
/**
* Stop the effect from executing
*/
stop: Fn
/**
* Start the effects
*/
start: Fn
}
/**
* @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;
}