types: improve ref sugar $computed typing

This commit is contained in:
Evan You
2021-08-20 00:07:16 -04:00
parent 872b3f7ec5
commit 4adc5042f9
2 changed files with 44 additions and 5 deletions

View File

@@ -1,3 +1,4 @@
import { WritableComputedRef } from '@vue/reactivity'
import {
expectType,
$ref,
@@ -22,7 +23,19 @@ expectType<{ foo: Ref<number> }>($shallowRef({ foo: ref(1) }))
// $computed
expectType<number>($computed(() => 1))
let b = $ref(1)
expectType<number>($computed(() => b))
expectType<number>(
$computed(() => b, {
onTrack() {}
})
)
// writable computed
expectType<number>(
$computed({
get: () => 1,
set: () => {}
})
)
function useFoo() {
return {
@@ -45,3 +58,10 @@ expectType<Ref<string>>($raw(y))
const c = $computed(() => 1)
const cRef = $raw(c)
expectType<ComputedRef<number>>(cRef)
const c2 = $computed({
get: () => 1,
set: () => {}
})
const c2Ref = $raw(c2)
expectType<WritableComputedRef<number>>(c2Ref)