types: improve ref sugar $computed typing
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user