/
types.d.ts
300 lines (263 loc) · 7.65 KB
/
types.d.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
import type {
ComputedGetter,
ComputedRefSymbol,
DebuggerOptions,
RawSymbol,
ReactiveEffect,
RefSymbol,
RefUnwrapBailTypes,
ShallowReactiveMarker,
ShallowRefMarker,
WritableComputedOptions,
} from '@vue/reactivity/dist/reactivity'
import type { IfAny } from '@vue/shared'
export {
ReactiveFlags,
DebuggerEventExtraInfo,
DebuggerEvent,
DebuggerOptions,
RefUnwrapBailTypes,
ComputedGetter,
ComputedSetter,
WritableComputedOptions,
TriggerOpTypes,
shallowReadonly,
resetTracking,
TrackOpTypes,
EffectScheduler,
ReactiveEffect,
EffectScope,
effectScope,
enableTracking,
getCurrentScope,
isProxy,
isReactive,
isReadonly,
isShallow,
toRaw,
track,
trigger,
onScopeDispose,
pauseTracking,
ReactiveEffectRunner,
stop,
ReactiveEffectOptions,
effect,
ITERATE_KEY,
ShallowRefMarker,
RawSymbol,
RefSymbol,
ShallowReactiveMarker,
ComputedRefImpl,
ComputedRefSymbol,
pauseScheduling,
resetScheduling,
} from '@vue/reactivity/dist/reactivity'
declare type Primitive =
| string
| number
| boolean
| bigint
| symbol
| undefined
| null
declare type BaseTypes = string | number | boolean
declare type Builtin = Primitive | Function | Date | Error | RegExp
declare type WeakCollections = WeakMap<any, any> | WeakSet<any>
declare type IterableCollections = Map<any, any> | Set<any>
declare type CollectionTypes = IterableCollections | WeakCollections
export declare type FunctionalRef<
T = any,
Writable extends boolean = boolean,
> = {
(): T
} & (Writable extends true
? {
set: (value: T) => void
mutate: (mutator: (value: T) => void) => void
}
: {})
export declare interface ComputedRef<T = any> extends WritableComputedRef<T> {
set: never
readonly value: T
[ComputedRefSymbol]: true
}
export declare function computed<T>(
getter: ComputedGetter<T>,
debugOptions?: DebuggerOptions,
): ComputedRef<T>
export declare function computed<T>(
options: WritableComputedOptions<T>,
debugOptions?: DebuggerOptions,
): WritableComputedRef<T>
export declare function deferredComputed<T>(getter: () => T): ComputedRef<T>
export declare type CustomRefFactory<T> = (
track: () => void,
trigger: () => void,
) => {
get: () => T
set: (value: T) => void
}
export declare function customRef<T>(factory: CustomRefFactory<T>): Ref<T>
export type ReadonlyRef<T> = Omit<Readonly<T>, 'set'> & FunctionalRef<T, false>
export declare type DeepReadonly<T> =
T extends Ref<infer U>
? ReadonlyRef<Ref<DeepReadonly<U>>>
: T extends Builtin
? T
: T extends Map<infer K, infer V>
? ReadonlyMap<DeepReadonly<K>, DeepReadonly<V>>
: T extends ReadonlyMap<infer K, infer V>
? ReadonlyMap<DeepReadonly<K>, DeepReadonly<V>>
: T extends WeakMap<infer K, infer V>
? WeakMap<DeepReadonly<K>, DeepReadonly<V>>
: T extends Set<infer U>
? ReadonlySet<DeepReadonly<U>>
: T extends ReadonlySet<infer U>
? ReadonlySet<DeepReadonly<U>>
: T extends WeakSet<infer U>
? WeakSet<DeepReadonly<U>>
: T extends Promise<infer U>
? Promise<DeepReadonly<U>>
: T extends Ref<infer U>
? Readonly<Ref<DeepReadonly<U>>>
: T extends {}
? {
readonly [K in keyof T]: DeepReadonly<T[K]>
}
: Readonly<T>
export declare function isRef<T>(r: Ref<T> | unknown): r is Ref<T>
export declare function markRaw<T extends object>(
value: T,
): T & {
[RawSymbol]?: true
}
export declare function proxyRefs<T extends object>(
objectWithRefs: T,
): ShallowUnwrapRef<T>
/**
* Creates a reactive copy of the original object.
*
* The reactive conversion is "deep"—it affects all nested properties. In the
* ES2015 Proxy based implementation, the returned proxy is **not** equal to the
* original object. It is recommended to work exclusively with the reactive
* proxy and avoid relying on the original object.
*
* A reactive object also automatically unwraps refs contained in it, so you
* don't need to use `.value` when accessing and mutating their value:
*
* ```js
* const count = ref(0)
* const obj = reactive({
* count
* })
*
* obj.count++
* obj.count // -> 1
* count.value // -> 1
* ```
*/
export declare function reactive<T extends object>(
target: T,
): UnwrapNestedRefs<T>
/**
* Creates a readonly copy of the original object. Note the returned copy is not
* made reactive, but `readonly` can be called on an already reactive object.
*/
export declare function readonly<T extends object>(
target: T,
): DeepReadonly<UnwrapNestedRefs<T>>
export declare interface Ref<T = any> extends FunctionalRef<T, true> {
value: T
/**
* Type differentiator only.
* We need this to be in public d.ts but don't want it to show up in IDE
* autocomplete, so we use a private Symbol instead.
*/
[RefSymbol]: true
}
export declare function ref<T extends object>(
value: T,
): [T] extends [Ref] ? T : Ref<UnwrapRef<T>>
export declare function ref<T>(value: T): Ref<UnwrapRef<T>>
export declare function ref<T = any>(): Ref<T | undefined>
export declare type ShallowReactive<T> = T & {
[ShallowReactiveMarker]?: true
}
/**
* Return a shallowly-reactive copy of the original object, where only the root
* level properties are reactive. It also does not auto-unwrap refs (even at the
* root level).
*/
export declare function shallowReactive<T extends object>(
target: T,
): ShallowReactive<T>
export declare type ShallowRef<T = any> = Ref<T> & {
[ShallowRefMarker]?: true
}
export declare function shallowRef<T extends object>(
value: T,
): T extends Ref ? T : ShallowRef<T>
export declare function shallowRef<T>(value: T): ShallowRef<T>
export declare function shallowRef<T = any>(): ShallowRef<T | undefined>
export declare type ShallowUnwrapRef<T> = {
[K in keyof T]: T[K] extends Ref<infer V>
? V
: T[K] extends Ref<infer V> | undefined
? unknown extends V
? undefined
: V | undefined
: T[K]
}
export declare type ToRef<T> = IfAny<T, Ref<T>, [T] extends [Ref] ? T : Ref<T>>
export declare function toRef<T extends object, K extends keyof T>(
object: T,
key: K,
): ToRef<T[K]>
export declare function toRef<T extends object, K extends keyof T>(
object: T,
key: K,
defaultValue: T[K],
): ToRef<Exclude<T[K], undefined>>
export declare type ToRefs<T = any> = {
[K in keyof T]: ToRef<T[K]>
}
export declare function toRefs<T extends object>(object: T): ToRefs<T>
export declare function triggerRef(ref: Ref): void
export declare function unref<T>(ref: T | Ref<T>): T
export declare type UnwrapNestedRefs<T> = T extends Ref ? T : UnwrapRefSimple<T>
export declare type UnwrapRef<T> =
T extends ShallowRef<infer V>
? V
: T extends Ref<infer V>
? UnwrapRefSimple<V>
: UnwrapRefSimple<T>
declare type UnwrapRefSimple<T> = T extends
| Function
| CollectionTypes
| BaseTypes
| Ref
| RefUnwrapBailTypes[keyof RefUnwrapBailTypes]
| {
[RawSymbol]?: true
}
? T
: T extends Array<any>
? {
[K in keyof T]: UnwrapRefSimple<T[K]>
}
: T extends object & {
[ShallowReactiveMarker]?: never
}
? {
[P in keyof T]: P extends symbol ? T[P] : UnwrapRef<T[P]>
}
: T
export declare interface WritableComputedRef<T> extends Ref<T> {
readonly effect: ReactiveEffect<T>
}
export type MaybeRef<T = any> = T | Ref<T>
export type MaybeRefOrGetter<T = any> = MaybeRef<T> | (() => T)
export declare function toValue<T>(
source: MaybeRefOrGetter<T> | ComputedRef<T>,
): T