Skip to content

Commit

Permalink
fix(types): ref() return type should not be any when initial value is…
Browse files Browse the repository at this point in the history
… any
  • Loading branch information
Alfred-Skyblue committed Dec 14, 2023
1 parent 305e4ae commit f9d3b11
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
1 change: 0 additions & 1 deletion src/v3/reactivity/ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export function isRef(r: any): r is Ref {
return !!(r && (r as Ref).__v_isRef === true)
}

export function ref<T extends Ref>(value: T): T
export function ref<T>(value: T): Ref<UnwrapRef<T>>
export function ref<T = any>(): Ref<T | undefined>
export function ref(value?: unknown) {
Expand Down
15 changes: 12 additions & 3 deletions types/test/v3/reactivity-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<number>) {
// ref coercing
Expand Down Expand Up @@ -46,6 +46,10 @@ function plainType(arg: number | Ref<number>) {
expectType<Ref<true>>(trueRef)
expectType<true>(trueRef.value)

// any value should return Ref<any>, not any
const a = ref(1 as any)
expectType<IsAny<typeof a>>(false)

// tuple
expectType<[number, string]>(unref(ref([1, '1'])))

Expand Down Expand Up @@ -386,7 +390,6 @@ describe('set/del', () => {
del([], 'fse', 123)
})


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

expectType<IsUnion<typeof shallowUnionGenParam>>(false)
expectType<IsUnion<typeof shallowUnionAsCast>>(false)
}
}

{
// any value should return Ref<any>, not any
const a = shallowRef(1 as any)
expectType<IsAny<typeof a>>(false)
}

0 comments on commit f9d3b11

Please sign in to comment.