diff --git a/packages/reactivity/src/ref.ts b/packages/reactivity/src/ref.ts index fd8ac821..0414ece2 100644 --- a/packages/reactivity/src/ref.ts +++ b/packages/reactivity/src/ref.ts @@ -85,7 +85,7 @@ export function triggerRef(ref: Ref) { trigger(toRaw(ref), TriggerOpTypes.SET, 'value', __DEV__ ? ref.value : void 0) } -export function unref(ref: T): T extends Ref ? V : T { +export function unref(ref: T | Ref): T { return isRef(ref) ? (ref.value as any) : ref } diff --git a/test-dts/ref.test-d.ts b/test-dts/ref.test-d.ts index a0887ca4..74bb7829 100644 --- a/test-dts/ref.test-d.ts +++ b/test-dts/ref.test-d.ts @@ -203,3 +203,10 @@ switch (data.state.value) { data.state.value = 'state1' break } + +// #3954 +function testUnrefGenerics(p: T | Ref) { + expectType(unref(p)) +} + +testUnrefGenerics(1)