Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(types): ref() return type should not be any when initial value is any #13132

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion src/v3/reactivity/ref.ts
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
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)
}