ref.test-d.ts 352 B

123456789101112131415161718
  1. import { expectType } from 'tsd'
  2. import { Ref, ref, isRef, unref } from './index'
  3. function foo(arg: number | Ref<number>) {
  4. // ref coercing
  5. const coerced = ref(arg)
  6. expectType<Ref<number>>(coerced)
  7. // isRef as type guard
  8. if (isRef(arg)) {
  9. expectType<Ref<number>>(arg)
  10. }
  11. // ref unwrapping
  12. expectType<number>(unref(arg))
  13. }
  14. foo(1)