vue3-yuanma/test-dts/ref.test-d.ts

19 lines
352 B
TypeScript
Raw Normal View History

import { expectType } from 'tsd'
import { Ref, ref, isRef, unref } from './index'
function foo(arg: number | Ref<number>) {
// ref coercing
const coerced = ref(arg)
expectType<Ref<number>>(coerced)
// isRef as type guard
if (isRef(arg)) {
expectType<Ref<number>>(arg)
}
// ref unwrapping
expectType<number>(unref(arg))
}
foo(1)