Skip to content

Commit 28b4c31

Browse files
authored
feat(types): expose ToRefs type (#1037)
1 parent c9f10be commit 28b4c31

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

packages/reactivity/src/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ export {
88
customRef,
99
triggerRef,
1010
Ref,
11-
UnwrapRef
11+
UnwrapRef,
12+
ToRefs
1213
} from './ref'
1314
export {
1415
reactive,

packages/reactivity/src/ref.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ export interface Ref<T = any> {
2020
value: T
2121
}
2222

23+
export type ToRefs<T = any> = { [K in keyof T]: Ref<T[K]> }
24+
2325
const convert = <T extends unknown>(val: T): T =>
2426
isObject(val) ? reactive(val) : val
2527

@@ -108,9 +110,7 @@ export function customRef<T>(factory: CustomRefFactory<T>): Ref<T> {
108110
return r as any
109111
}
110112

111-
export function toRefs<T extends object>(
112-
object: T
113-
): { [K in keyof T]: Ref<T[K]> } {
113+
export function toRefs<T extends object>(object: T): ToRefs<T> {
114114
if (__DEV__ && !isProxy(object)) {
115115
console.warn(`toRefs() expects a reactive object but received a plain one.`)
116116
}

packages/runtime-core/src/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ export {
153153
Ref,
154154
ComputedRef,
155155
UnwrapRef,
156-
WritableComputedOptions
156+
WritableComputedOptions,
157+
ToRefs
157158
} from '@vue/reactivity'
158159
export {
159160
// types

0 commit comments

Comments
 (0)