feat(types): expose ToRefs type (#1037)

This commit is contained in:
Carlos Rodrigues 2020-04-24 18:10:16 +01:00 committed by GitHub
parent c9f10be9de
commit 28b4c317b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 5 deletions

View File

@ -8,7 +8,8 @@ export {
customRef, customRef,
triggerRef, triggerRef,
Ref, Ref,
UnwrapRef UnwrapRef,
ToRefs
} from './ref' } from './ref'
export { export {
reactive, reactive,

View File

@ -20,6 +20,8 @@ export interface Ref<T = any> {
value: T value: T
} }
export type ToRefs<T = any> = { [K in keyof T]: Ref<T[K]> }
const convert = <T extends unknown>(val: T): T => const convert = <T extends unknown>(val: T): T =>
isObject(val) ? reactive(val) : val isObject(val) ? reactive(val) : val
@ -108,9 +110,7 @@ export function customRef<T>(factory: CustomRefFactory<T>): Ref<T> {
return r as any return r as any
} }
export function toRefs<T extends object>( export function toRefs<T extends object>(object: T): ToRefs<T> {
object: T
): { [K in keyof T]: Ref<T[K]> } {
if (__DEV__ && !isProxy(object)) { if (__DEV__ && !isProxy(object)) {
console.warn(`toRefs() expects a reactive object but received a plain one.`) console.warn(`toRefs() expects a reactive object but received a plain one.`)
} }

View File

@ -153,7 +153,8 @@ export {
Ref, Ref,
ComputedRef, ComputedRef,
UnwrapRef, UnwrapRef,
WritableComputedOptions WritableComputedOptions,
ToRefs
} from '@vue/reactivity' } from '@vue/reactivity'
export { export {
// types // types