|
| 1 | +import { |
| 2 | + Ref, |
| 3 | + UnwrapRef, |
| 4 | + ComputedRef, |
| 5 | + WritableComputedOptions, |
| 6 | + DebuggerOptions, |
| 7 | + WritableComputedRef, |
| 8 | + CustomRefFactory |
| 9 | +} from '@vue/runtime-dom' |
| 10 | + |
| 11 | +export declare const RefType: unique symbol |
| 12 | + |
| 13 | +export declare const enum RefTypes { |
| 14 | + Ref = 1, |
| 15 | + ComputedRef = 2, |
| 16 | + WritableComputedRef = 3 |
| 17 | +} |
| 18 | + |
| 19 | +type RefValue<T> = T extends null | undefined |
| 20 | + ? T |
| 21 | + : T & { [RefType]?: RefTypes.Ref } |
| 22 | + |
| 23 | +type ComputedRefValue<T> = T extends null | undefined |
| 24 | + ? T |
| 25 | + : T & { [RefType]?: RefTypes.ComputedRef } |
| 26 | + |
| 27 | +type WritableComputedRefValue<T> = T extends null | undefined |
| 28 | + ? T |
| 29 | + : T & { [RefType]?: RefTypes.WritableComputedRef } |
| 30 | + |
| 31 | +type NormalObject<T extends object> = T & { [RefType]?: never } |
| 32 | + |
| 33 | +/** |
| 34 | + * Vue ref transform macro for binding refs as reactive variables. |
| 35 | + */ |
| 36 | +export declare function $<T>(arg: ComputedRef<T>): ComputedRefValue<T> |
| 37 | +export declare function $<T>( |
| 38 | + arg: WritableComputedRef<T> |
| 39 | +): WritableComputedRefValue<T> |
| 40 | +export declare function $<T>(arg: Ref<T>): RefValue<T> |
| 41 | +export declare function $<T extends object>(arg?: T): DestructureRefs<T> |
| 42 | + |
| 43 | +type DestructureRefs<T extends object> = { |
| 44 | + [K in keyof T]: T[K] extends ComputedRef<infer V> |
| 45 | + ? ComputedRefValue<V> |
| 46 | + : T[K] extends WritableComputedRef<infer V> |
| 47 | + ? WritableComputedRefValue<V> |
| 48 | + : T[K] extends Ref<infer V> |
| 49 | + ? RefValue<V> |
| 50 | + : T[K] |
| 51 | +} |
| 52 | + |
| 53 | +/** |
| 54 | + * Vue ref transform macro for accessing underlying refs of reactive varaibles. |
| 55 | + */ |
| 56 | +export declare function $$<T extends object>(arg: NormalObject<T>): ToRawRefs<T> |
| 57 | +export declare function $$<T>(value: RefValue<T>): Ref<T> |
| 58 | +export declare function $$<T>(value: ComputedRefValue<T>): ComputedRef<T> |
| 59 | +export declare function $$<T>( |
| 60 | + value: WritableComputedRefValue<T> |
| 61 | +): WritableComputedRef<T> |
| 62 | + |
| 63 | +type ToRawRefs<T extends object> = { |
| 64 | + [K in keyof T]: T[K] extends RefValue<infer V> |
| 65 | + ? Ref<V> |
| 66 | + : T[K] extends ComputedRefValue<infer V> |
| 67 | + ? ComputedRef<V> |
| 68 | + : T[K] extends WritableComputedRefValue<infer V> |
| 69 | + ? WritableComputedRef<V> |
| 70 | + : T[K] extends object |
| 71 | + ? T[K] extends |
| 72 | + | Function |
| 73 | + | Map<any, any> |
| 74 | + | Set<any> |
| 75 | + | WeakMap<any, any> |
| 76 | + | WeakSet<any> |
| 77 | + ? T[K] |
| 78 | + : ToRawRefs<T[K]> |
| 79 | + : T[K] |
| 80 | +} |
| 81 | + |
| 82 | +export declare function $ref<T>(arg?: T | Ref<T>): RefValue<UnwrapRef<T>> |
| 83 | + |
| 84 | +export declare function $shallowRef<T>(arg?: T): RefValue<T> |
| 85 | + |
| 86 | +export declare function $toRef<T extends object, K extends keyof T>( |
| 87 | + object: T, |
| 88 | + key: K |
| 89 | +): RefValue<T[K]> |
| 90 | + |
| 91 | +export declare function $toRef<T extends object, K extends keyof T>( |
| 92 | + object: T, |
| 93 | + key: K, |
| 94 | + defaultValue: T[K] |
| 95 | +): RefValue<Exclude<T[K], undefined>> |
| 96 | + |
| 97 | +export declare function $customRef<T>(factory: CustomRefFactory<T>): RefValue<T> |
| 98 | + |
| 99 | +export declare function $computed<T>( |
| 100 | + getter: () => T, |
| 101 | + debuggerOptions?: DebuggerOptions |
| 102 | +): ComputedRefValue<T> |
| 103 | +export declare function $computed<T>( |
| 104 | + options: WritableComputedOptions<T>, |
| 105 | + debuggerOptions?: DebuggerOptions |
| 106 | +): WritableComputedRefValue<T> |
0 commit comments