types: typing for ref macros
This commit is contained in:
42
test-dts/refMacros.test-d.ts
Normal file
42
test-dts/refMacros.test-d.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import {
|
||||
expectType,
|
||||
$ref,
|
||||
$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) }))
|
||||
|
||||
// $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)
|
||||
Reference in New Issue
Block a user