refSugar.test-d.ts 834 B

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