2021-07-17 05:35:04 +08:00
|
|
|
import {
|
|
|
|
expectType,
|
|
|
|
$ref,
|
2021-08-11 22:19:58 +08:00
|
|
|
$shallowRef,
|
2021-07-17 05:35:04 +08:00
|
|
|
$computed,
|
|
|
|
$fromRefs,
|
|
|
|
$raw,
|
|
|
|
ref,
|
|
|
|
Ref,
|
|
|
|
ComputedRef
|
|
|
|
} from './index'
|
|
|
|
|
|
|
|
// $ref
|
|
|
|
expectType<number>($ref(1))
|
|
|
|
expectType<number>($ref(ref(1)))
|
|
|
|
expectType<{ foo: number }>($ref({ foo: ref(1) }))
|
|
|
|
|
2021-08-11 22:19:58 +08:00
|
|
|
// $shallowRef
|
|
|
|
expectType<number>($shallowRef(1))
|
|
|
|
expectType<{ foo: Ref<number> }>($shallowRef({ foo: ref(1) }))
|
|
|
|
|
2021-07-17 05:35:04 +08:00
|
|
|
// $computed
|
|
|
|
expectType<number>($computed(() => 1))
|
|
|
|
let b = $ref(1)
|
|
|
|
expectType<number>($computed(() => b))
|
|
|
|
|
|
|
|
function useFoo() {
|
|
|
|
return {
|
|
|
|
x: ref(1),
|
|
|
|
y: ref('hi'),
|
|
|
|
z: 123
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// $fromRefs
|
|
|
|
const { x, y, z } = $fromRefs(useFoo())
|
|
|
|
expectType<number>(x)
|
|
|
|
expectType<string>(y)
|
|
|
|
expectType<number>(z)
|
|
|
|
|
|
|
|
// $raw
|
|
|
|
expectType<Ref<number>>($raw(x))
|
|
|
|
expectType<Ref<string>>($raw(y))
|
|
|
|
|
|
|
|
const c = $computed(() => 1)
|
|
|
|
const cRef = $raw(c)
|
|
|
|
expectType<ComputedRef<number>>(cRef)
|