2020-02-22 00:45:42 +08:00
|
|
|
import { expectType } from 'tsd'
|
2020-02-22 11:39:32 +08:00
|
|
|
import { Ref, ref, isRef, unref } from './index'
|
2020-02-22 00:45:42 +08:00
|
|
|
|
|
|
|
function foo(arg: number | Ref<number>) {
|
|
|
|
// ref coercing
|
|
|
|
const coerced = ref(arg)
|
|
|
|
expectType<Ref<number>>(coerced)
|
|
|
|
|
|
|
|
// isRef as type guard
|
|
|
|
if (isRef(arg)) {
|
|
|
|
expectType<Ref<number>>(arg)
|
|
|
|
}
|
2020-02-22 11:39:32 +08:00
|
|
|
|
|
|
|
// ref unwrapping
|
|
|
|
expectType<number>(unref(arg))
|
2020-02-26 08:44:06 +08:00
|
|
|
|
|
|
|
// ref inner type should be unwrapped
|
|
|
|
const nestedRef = ref({
|
|
|
|
foo: ref(1)
|
|
|
|
})
|
|
|
|
expectType<Ref<{ foo: number }>>(nestedRef)
|
2020-02-26 09:38:02 +08:00
|
|
|
expectType<{ foo: number }>(nestedRef.value)
|
2020-02-22 00:45:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
foo(1)
|