diff --git a/packages/reactivity/src/ref.ts b/packages/reactivity/src/ref.ts index 396e34e4..83bef572 100644 --- a/packages/reactivity/src/ref.ts +++ b/packages/reactivity/src/ref.ts @@ -35,7 +35,10 @@ export function ref(value?: unknown) { return createRef(value) } -export function shallowRef(value: T): T extends Ref ? T : Ref +export function shallowRef( + value: T +): T extends Ref ? T : Ref +export function shallowRef(value: T): Ref export function shallowRef(): Ref export function shallowRef(value?: unknown) { return createRef(value, true) diff --git a/test-dts/ref.test-d.ts b/test-dts/ref.test-d.ts index 6430b15c..c961f4be 100644 --- a/test-dts/ref.test-d.ts +++ b/test-dts/ref.test-d.ts @@ -1,6 +1,7 @@ import { Ref, ref, + shallowRef, isRef, unref, reactive, @@ -120,6 +121,22 @@ const state = reactive({ expectType(state.foo.label) +// shallowRef +type Status = 'initial' | 'ready' | 'invalidating' +const shallowStatus = shallowRef('initial') +if (shallowStatus.value === 'initial') { + expectType>(shallowStatus) + expectType(shallowStatus.value) + shallowStatus.value = 'invalidating' +} + +const refStatus = ref('initial') +if (refStatus.value === 'initial') { + expectType>(shallowStatus) + expectType(shallowStatus.value) + refStatus.value = 'invalidating' +} + // proxyRefs: should return `reactive` directly const r1 = reactive({ k: 'v'