diff --git a/packages/dts-test/ref.test-d.ts b/packages/dts-test/ref.test-d.ts index 542d9d6a9ef..a467c446d0a 100644 --- a/packages/dts-test/ref.test-d.ts +++ b/packages/dts-test/ref.test-d.ts @@ -18,7 +18,7 @@ import { computed, ShallowRef } from 'vue' -import { expectType, describe, IsUnion } from './utils' +import { expectType, describe, IsUnion, IsAny } from './utils' function plainType(arg: number | Ref) { // ref coercing @@ -79,6 +79,10 @@ function plainType(arg: number | Ref) { // should still unwrap in objects nested in arrays const arr2 = ref([{ a: ref(1) }]).value expectType(arr2[0].a) + + // any value should return Ref, not any + const a = ref(1 as any) + expectType>(false) } plainType(1) @@ -191,6 +195,12 @@ if (refStatus.value === 'initial') { expectType>(false) } +{ + // any value should return Ref, not any + const a = shallowRef(1 as any) + expectType>(false) +} + describe('shallowRef with generic', () => { const r = ref({}) as MaybeRef expectType | Ref>(shallowRef(r)) diff --git a/packages/reactivity/src/ref.ts b/packages/reactivity/src/ref.ts index 201766158ed..7e67de7b661 100644 --- a/packages/reactivity/src/ref.ts +++ b/packages/reactivity/src/ref.ts @@ -88,7 +88,6 @@ export function isRef(r: any): r is Ref { * @param value - The object to wrap in the ref. * @see {@link https://vuejs.org/api/reactivity-core.html#ref} */ -export function ref(value: T): T export function ref(value: T): Ref> export function ref(): Ref export function ref(value?: unknown) {