Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

types(reactivity): creating type for return toRefs and export return type #1037

Merged
merged 1 commit into from
Apr 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/reactivity/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ export {
customRef,
triggerRef,
Ref,
UnwrapRef
UnwrapRef,
ToRefs
} from './ref'
export {
reactive,
Expand Down
6 changes: 3 additions & 3 deletions packages/reactivity/src/ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export interface Ref<T = any> {
value: T
}

export type ToRefs<T = any> = { [K in keyof T]: Ref<T[K]> }

const convert = <T extends unknown>(val: T): T =>
isObject(val) ? reactive(val) : val

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

export function toRefs<T extends object>(
object: T
): { [K in keyof T]: Ref<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.`)
}
Expand Down
3 changes: 2 additions & 1 deletion packages/runtime-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ export {
Ref,
ComputedRef,
UnwrapRef,
WritableComputedOptions
WritableComputedOptions,
ToRefs
} from '@vue/reactivity'
export {
// types
Expand Down