ref-macros.d.ts 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import {
  2. Ref,
  3. UnwrapRef,
  4. ComputedRef,
  5. WritableComputedOptions,
  6. DebuggerOptions,
  7. WritableComputedRef,
  8. ShallowUnwrapRef
  9. } from '@vue/runtime-dom'
  10. declare const RefMarker: unique symbol
  11. type RefValue<T> = T & { [RefMarker]?: any }
  12. declare const ComputedRefMarker: unique symbol
  13. type ComputedRefValue<T> = T & { [ComputedRefMarker]?: any }
  14. declare const WritableComputedRefMarker: unique symbol
  15. type WritableComputedRefValue<T> = T & { [WritableComputedRefMarker]?: any }
  16. /**
  17. * Vue ref transform macro for binding refs as reactive variables.
  18. */
  19. declare function _$<T>(arg: ComputedRef<T>): ComputedRefValue<T>
  20. declare function _$<T>(arg: WritableComputedRef<T>): WritableComputedRefValue<T>
  21. declare function _$<T>(arg: Ref<T>): RefValue<T>
  22. declare function _$<T extends object>(arg?: T): ShallowUnwrapRef<T>
  23. /**
  24. * Vue ref transform macro for accessing underlying refs of reactive varaibles.
  25. */
  26. declare function _$$<T>(value: T): ComputedRef<T>
  27. declare function _$$<T>(
  28. value: WritableComputedRefValue<T>
  29. ): WritableComputedRef<T>
  30. declare function _$$<T>(value: RefValue<T>): Ref<T>
  31. declare function _$$<T extends object>(arg: T): ToRawRefs<T>
  32. type ToRawRefs<T extends object> = {
  33. [K in keyof T]: T[K] extends ComputedRefValue<infer V>
  34. ? ComputedRefValue<V>
  35. : T[K] extends WritableComputedRefValue<infer V>
  36. ? WritableComputedRef<V>
  37. : T[K] extends RefValue<infer V>
  38. ? Ref<V>
  39. : T[K] extends object
  40. ? T[K] extends
  41. | Function
  42. | Map<any, any>
  43. | Set<any>
  44. | WeakMap<any, any>
  45. | WeakSet<any>
  46. ? T[K]
  47. : ToRawRefs<T[K]>
  48. : T[K]
  49. }
  50. declare function _$ref<T>(arg?: T | Ref<T>): RefValue<UnwrapRef<T>>
  51. declare function _$shallowRef<T>(arg?: T): RefValue<T>
  52. declare function _$computed<T>(
  53. getter: () => T,
  54. debuggerOptions?: DebuggerOptions
  55. ): ComputedRefValue<T>
  56. declare function _$computed<T>(
  57. options: WritableComputedOptions<T>,
  58. debuggerOptions?: DebuggerOptions
  59. ): WritableComputedRefValue<T>
  60. declare global {
  61. const $: typeof _$
  62. const $$: typeof _$$
  63. const $ref: typeof _$ref
  64. const $shallowRef: typeof _$shallowRef
  65. const $computed: typeof _$computed
  66. }