refSugar.test-d.ts 705 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import {
  2. expectType,
  3. $ref,
  4. $computed,
  5. $fromRefs,
  6. $raw,
  7. ref,
  8. Ref,
  9. ComputedRef
  10. } from './index'
  11. // $ref
  12. expectType<number>($ref(1))
  13. expectType<number>($ref(ref(1)))
  14. expectType<{ foo: number }>($ref({ foo: ref(1) }))
  15. // $computed
  16. expectType<number>($computed(() => 1))
  17. let b = $ref(1)
  18. expectType<number>($computed(() => b))
  19. function useFoo() {
  20. return {
  21. x: ref(1),
  22. y: ref('hi'),
  23. z: 123
  24. }
  25. }
  26. // $fromRefs
  27. const { x, y, z } = $fromRefs(useFoo())
  28. expectType<number>(x)
  29. expectType<string>(y)
  30. expectType<number>(z)
  31. // $raw
  32. expectType<Ref<number>>($raw(x))
  33. expectType<Ref<string>>($raw(y))
  34. const c = $computed(() => 1)
  35. const cRef = $raw(c)
  36. expectType<ComputedRef<number>>(cRef)