Skip to content

Commit f9d3b11

Browse files
fix(types): ref() return type should not be any when initial value is any
1 parent 305e4ae commit f9d3b11

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/v3/reactivity/ref.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ export function isRef(r: any): r is Ref {
4040
return !!(r && (r as Ref).__v_isRef === true)
4141
}
4242

43-
export function ref<T extends Ref>(value: T): T
4443
export function ref<T>(value: T): Ref<UnwrapRef<T>>
4544
export function ref<T = any>(): Ref<T | undefined>
4645
export function ref(value?: unknown) {

types/test/v3/reactivity-test.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
set,
1616
del
1717
} from '../../index'
18-
import { IsUnion, describe, expectType } from '../utils'
18+
import { IsUnion, describe, expectType, IsAny } from '../utils'
1919

2020
function plainType(arg: number | Ref<number>) {
2121
// ref coercing
@@ -46,6 +46,10 @@ function plainType(arg: number | Ref<number>) {
4646
expectType<Ref<true>>(trueRef)
4747
expectType<true>(trueRef.value)
4848

49+
// any value should return Ref<any>, not any
50+
const a = ref(1 as any)
51+
expectType<IsAny<typeof a>>(false)
52+
4953
// tuple
5054
expectType<[number, string]>(unref(ref([1, '1'])))
5155

@@ -386,7 +390,6 @@ describe('set/del', () => {
386390
del([], 'fse', 123)
387391
})
388392

389-
390393
{
391394
//#12978
392395
type Steps = { step: '1' } | { step: '2' }
@@ -395,4 +398,10 @@ describe('set/del', () => {
395398

396399
expectType<IsUnion<typeof shallowUnionGenParam>>(false)
397400
expectType<IsUnion<typeof shallowUnionAsCast>>(false)
398-
}
401+
}
402+
403+
{
404+
// any value should return Ref<any>, not any
405+
const a = shallowRef(1 as any)
406+
expectType<IsAny<typeof a>>(false)
407+
}

0 commit comments

Comments
 (0)