2021-08-20 12:07:16 +08:00
|
|
|
import { WritableComputedRef } from '@vue/reactivity'
|
2021-08-24 08:35:12 +08:00
|
|
|
import { expectType, ref, Ref, ComputedRef } from './index'
|
|
|
|
import 'vue/ref-macros'
|
|
|
|
|
|
|
|
// wrapping refs
|
|
|
|
// normal
|
|
|
|
// computed
|
|
|
|
// writable computed
|
|
|
|
|
|
|
|
// destructure
|
|
|
|
const { x, y, z } = $(useFoo())
|
|
|
|
expectType<number>(x)
|
|
|
|
expectType<string>(y)
|
|
|
|
expectType<number>(z)
|
2021-07-17 05:35:04 +08:00
|
|
|
|
|
|
|
// $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)
|
2021-08-20 12:07:16 +08:00
|
|
|
expectType<number>(
|
|
|
|
$computed(() => b, {
|
|
|
|
onTrack() {}
|
|
|
|
})
|
|
|
|
)
|
|
|
|
|
|
|
|
// writable computed
|
|
|
|
expectType<number>(
|
|
|
|
$computed({
|
|
|
|
get: () => 1,
|
|
|
|
set: () => {}
|
|
|
|
})
|
|
|
|
)
|
2021-07-17 05:35:04 +08:00
|
|
|
|
|
|
|
function useFoo() {
|
|
|
|
return {
|
|
|
|
x: ref(1),
|
|
|
|
y: ref('hi'),
|
|
|
|
z: 123
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-24 08:35:12 +08:00
|
|
|
// $$
|
|
|
|
expectType<Ref<number>>($$(x))
|
|
|
|
expectType<Ref<string>>($$(y))
|
2021-07-17 05:35:04 +08:00
|
|
|
|
|
|
|
const c = $computed(() => 1)
|
2021-08-24 08:35:12 +08:00
|
|
|
const cRef = $$(c)
|
2021-07-17 05:35:04 +08:00
|
|
|
expectType<ComputedRef<number>>(cRef)
|
2021-08-20 12:07:16 +08:00
|
|
|
|
|
|
|
const c2 = $computed({
|
|
|
|
get: () => 1,
|
|
|
|
set: () => {}
|
|
|
|
})
|
2021-08-24 08:35:12 +08:00
|
|
|
const c2Ref = $$(c2)
|
2021-08-20 12:07:16 +08:00
|
|
|
expectType<WritableComputedRef<number>>(c2Ref)
|
2021-08-24 08:35:12 +08:00
|
|
|
|
|
|
|
// $$ on object
|