Skip to content

Commit a6e6253

Browse files
authored
types(reactivity): adjust type exports (#4407)
1 parent 4502a0e commit a6e6253

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

packages/reactivity/src/index.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export {
99
customRef,
1010
triggerRef,
1111
Ref,
12+
ToRef,
1213
ToRefs,
1314
UnwrapRef,
1415
ShallowUnwrapRef,
@@ -51,7 +52,8 @@ export {
5152
ReactiveEffectOptions,
5253
EffectScheduler,
5354
DebuggerOptions,
54-
DebuggerEvent
55+
DebuggerEvent,
56+
DebuggerEventExtraInfo
5557
} from './effect'
5658
export {
5759
effectScope,

packages/reactivity/src/ref.ts

+8-9
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { reactive, isProxy, toRaw, isReactive } from './reactive'
55
import { CollectionTypes } from './collectionHandlers'
66
import { createDep, Dep } from './dep'
77

8-
export declare const RefSymbol: unique symbol
8+
declare const RefSymbol: unique symbol
99

1010
export interface Ref<T = any> {
1111
value: T
@@ -60,13 +60,6 @@ export function triggerRefValue(ref: RefBase<any>, newVal?: any) {
6060
}
6161
}
6262

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-
7063
const convert = <T extends unknown>(val: T): T =>
7164
isObject(val) ? reactive(val) : val
7265

@@ -154,7 +147,7 @@ export function proxyRefs<T extends object>(
154147
: new Proxy(objectWithRefs, shallowUnwrapHandlers)
155148
}
156149

157-
export type CustomRefFactory<T> = (
150+
type CustomRefFactory<T> = (
158151
track: () => void,
159152
trigger: () => void
160153
) => {
@@ -192,6 +185,11 @@ export function customRef<T>(factory: CustomRefFactory<T>): Ref<T> {
192185
return new CustomRefImpl(factory) as any
193186
}
194187

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+
}
195193
export function toRefs<T extends object>(object: T): ToRefs<T> {
196194
if (__DEV__ && !isProxy(object)) {
197195
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> {
217215
}
218216
}
219217

218+
export type ToRef<T> = [T] extends [Ref] ? T : Ref<UnwrapRef<T>>
220219
export function toRef<T extends object, K extends keyof T>(
221220
object: T,
222221
key: K

packages/runtime-core/src/index.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -147,18 +147,19 @@ declare module '@vue/reactivity' {
147147
}
148148

149149
export {
150+
Ref,
151+
ToRef,
152+
ToRefs,
150153
ReactiveEffectOptions,
151154
DebuggerEvent,
152155
DebuggerOptions,
153156
TrackOpTypes,
154157
TriggerOpTypes,
155-
Ref,
156158
ComputedRef,
157159
WritableComputedRef,
158160
UnwrapRef,
159161
ShallowUnwrapRef,
160162
WritableComputedOptions,
161-
ToRefs,
162163
DeepReadonly
163164
} from '@vue/reactivity'
164165
export {

0 commit comments

Comments
 (0)