@@ -5,7 +5,7 @@ import { reactive, isProxy, toRaw, isReactive } from './reactive'
5
5
import { CollectionTypes } from './collectionHandlers'
6
6
import { createDep , Dep } from './dep'
7
7
8
- export declare const RefSymbol : unique symbol
8
+ declare const RefSymbol : unique symbol
9
9
10
10
export interface Ref < T = any > {
11
11
value : T
@@ -60,13 +60,6 @@ export function triggerRefValue(ref: RefBase<any>, newVal?: any) {
60
60
}
61
61
}
62
62
63
- export type ToRef < T > = [ T ] extends [ Ref ] ? T : Ref < UnwrapRef < T > >
64
- export type ToRefs < T = any > = {
65
- // #2687: somehow using ToRef<T[K]> here turns the resulting type into
66
- // a union of multiple Ref<*> types instead of a single Ref<* | *> type.
67
- [ K in keyof T ] : T [ K ] extends Ref ? T [ K ] : Ref < UnwrapRef < T [ K ] > >
68
- }
69
-
70
63
const convert = < T extends unknown > ( val : T ) : T =>
71
64
isObject ( val ) ? reactive ( val ) : val
72
65
@@ -154,7 +147,7 @@ export function proxyRefs<T extends object>(
154
147
: new Proxy ( objectWithRefs , shallowUnwrapHandlers )
155
148
}
156
149
157
- export type CustomRefFactory < T > = (
150
+ type CustomRefFactory < T > = (
158
151
track : ( ) => void ,
159
152
trigger : ( ) => void
160
153
) => {
@@ -192,6 +185,11 @@ export function customRef<T>(factory: CustomRefFactory<T>): Ref<T> {
192
185
return new CustomRefImpl ( factory ) as any
193
186
}
194
187
188
+ export type ToRefs < T = any > = {
189
+ // #2687: somehow using ToRef<T[K]> here turns the resulting type into
190
+ // a union of multiple Ref<*> types instead of a single Ref<* | *> type.
191
+ [ K in keyof T ] : T [ K ] extends Ref ? T [ K ] : Ref < UnwrapRef < T [ K ] > >
192
+ }
195
193
export function toRefs < T extends object > ( object : T ) : ToRefs < T > {
196
194
if ( __DEV__ && ! isProxy ( object ) ) {
197
195
console . warn ( `toRefs() expects a reactive object but received a plain one.` )
@@ -217,6 +215,7 @@ class ObjectRefImpl<T extends object, K extends keyof T> {
217
215
}
218
216
}
219
217
218
+ export type ToRef < T > = [ T ] extends [ Ref ] ? T : Ref < UnwrapRef < T > >
220
219
export function toRef < T extends object , K extends keyof T > (
221
220
object : T ,
222
221
key : K
0 commit comments