import { CollectionTypes } from './collectionHandlers'
import { createDep, Dep } from './dep'
-export declare const RefSymbol: unique symbol
+declare const RefSymbol: unique symbol
export interface Ref<T = any> {
value: T
}
}
-export type ToRef<T> = [T] extends [Ref] ? T : Ref<UnwrapRef<T>>
-export type ToRefs<T = any> = {
- // #2687: somehow using ToRef<T[K]> here turns the resulting type into
- // a union of multiple Ref<*> types instead of a single Ref<* | *> type.
- [K in keyof T]: T[K] extends Ref ? T[K] : Ref<UnwrapRef<T[K]>>
-}
-
const convert = <T extends unknown>(val: T): T =>
isObject(val) ? reactive(val) : val
: new Proxy(objectWithRefs, shallowUnwrapHandlers)
}
-export type CustomRefFactory<T> = (
+type CustomRefFactory<T> = (
track: () => void,
trigger: () => void
) => {
return new CustomRefImpl(factory) as any
}
+export type ToRefs<T = any> = {
+ // #2687: somehow using ToRef<T[K]> here turns the resulting type into
+ // a union of multiple Ref<*> types instead of a single Ref<* | *> type.
+ [K in keyof T]: T[K] extends Ref ? T[K] : Ref<UnwrapRef<T[K]>>
+}
export function toRefs<T extends object>(object: T): ToRefs<T> {
if (__DEV__ && !isProxy(object)) {
console.warn(`toRefs() expects a reactive object but received a plain one.`)
}
}
+export type ToRef<T> = [T] extends [Ref] ? T : Ref<UnwrapRef<T>>
export function toRef<T extends object, K extends keyof T>(
object: T,
key: K