From f9d3b116fc04af0a88ed7c6db566d2674bdcf3d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=B6=E8=BF=9C=E6=96=B9?= Date: Thu, 14 Dec 2023 20:42:57 +0800 Subject: [PATCH] fix(types): ref() return type should not be any when initial value is any --- src/v3/reactivity/ref.ts | 1 - types/test/v3/reactivity-test.ts | 15 ++++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/v3/reactivity/ref.ts b/src/v3/reactivity/ref.ts index 33495806da1..3babc5d9da2 100644 --- a/src/v3/reactivity/ref.ts +++ b/src/v3/reactivity/ref.ts @@ -40,7 +40,6 @@ export function isRef(r: any): r is Ref { return !!(r && (r as Ref).__v_isRef === true) } -export function ref(value: T): T export function ref(value: T): Ref> export function ref(): Ref export function ref(value?: unknown) { diff --git a/types/test/v3/reactivity-test.ts b/types/test/v3/reactivity-test.ts index c357bf8d5c7..a888b86c6a5 100644 --- a/types/test/v3/reactivity-test.ts +++ b/types/test/v3/reactivity-test.ts @@ -15,7 +15,7 @@ import { set, del } from '../../index' -import { IsUnion, describe, expectType } from '../utils' +import { IsUnion, describe, expectType, IsAny } from '../utils' function plainType(arg: number | Ref) { // ref coercing @@ -46,6 +46,10 @@ function plainType(arg: number | Ref) { expectType>(trueRef) expectType(trueRef.value) + // any value should return Ref, not any + const a = ref(1 as any) + expectType>(false) + // tuple expectType<[number, string]>(unref(ref([1, '1']))) @@ -386,7 +390,6 @@ describe('set/del', () => { del([], 'fse', 123) }) - { //#12978 type Steps = { step: '1' } | { step: '2' } @@ -395,4 +398,10 @@ describe('set/del', () => { expectType>(false) expectType>(false) -} \ No newline at end of file +} + +{ + // any value should return Ref, not any + const a = shallowRef(1 as any) + expectType>(false) +}