]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
types(reactivity): adjust type exports (#4407)
authorzhangenming <282126346@qq.com>
Wed, 1 Sep 2021 20:49:12 +0000 (04:49 +0800)
committerGitHub <noreply@github.com>
Wed, 1 Sep 2021 20:49:12 +0000 (16:49 -0400)
packages/reactivity/src/index.ts
packages/reactivity/src/ref.ts
packages/runtime-core/src/index.ts

index d26e87de9a8da8b7fa645004d31bddb11eb1c9d7..b15f4d807be3d2047d66282232f7c0db1a50371a 100644 (file)
@@ -9,6 +9,7 @@ export {
   customRef,
   triggerRef,
   Ref,
+  ToRef,
   ToRefs,
   UnwrapRef,
   ShallowUnwrapRef,
@@ -51,7 +52,8 @@ export {
   ReactiveEffectOptions,
   EffectScheduler,
   DebuggerOptions,
-  DebuggerEvent
+  DebuggerEvent,
+  DebuggerEventExtraInfo
 } from './effect'
 export {
   effectScope,
index 11bc4d35290ee0d00fa5556219a7af66c24a640a..382afaa8016dc311efa5e782987eae69cae8d619 100644 (file)
@@ -5,7 +5,7 @@ import { reactive, isProxy, toRaw, isReactive } from './reactive'
 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
@@ -60,13 +60,6 @@ export function triggerRefValue(ref: RefBase<any>, newVal?: any) {
   }
 }
 
-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
 
@@ -154,7 +147,7 @@ export function proxyRefs<T extends object>(
     : new Proxy(objectWithRefs, shallowUnwrapHandlers)
 }
 
-export type CustomRefFactory<T> = (
+type CustomRefFactory<T> = (
   track: () => void,
   trigger: () => void
 ) => {
@@ -192,6 +185,11 @@ export function customRef<T>(factory: CustomRefFactory<T>): Ref<T> {
   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.`)
@@ -217,6 +215,7 @@ class ObjectRefImpl<T extends object, K extends keyof T> {
   }
 }
 
+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
index 0ba1d9c2fa98f1d68b14bd82bbd3cdeb97b0bf00..b182f7e7472cf8915ca4b6122af7168b9f8d3b4c 100644 (file)
@@ -147,18 +147,19 @@ declare module '@vue/reactivity' {
 }
 
 export {
+  Ref,
+  ToRef,
+  ToRefs,
   ReactiveEffectOptions,
   DebuggerEvent,
   DebuggerOptions,
   TrackOpTypes,
   TriggerOpTypes,
-  Ref,
   ComputedRef,
   WritableComputedRef,
   UnwrapRef,
   ShallowUnwrapRef,
   WritableComputedOptions,
-  ToRefs,
   DeepReadonly
 } from '@vue/reactivity'
 export {