From 327c8983fb9b04c7f819cd0c5a2b3d4ff69c7822 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 16 Jul 2021 17:35:04 -0400 Subject: [PATCH] types: typing for ref macros --- .../runtime-core/src/helpers/refMacros.ts | 21 ++++++++++ packages/runtime-core/src/index.ts | 11 +++-- .../types/scriptSetupHelpers.d.ts | 10 +++++ test-dts/refMacros.test-d.ts | 42 +++++++++++++++++++ 4 files changed, 80 insertions(+), 4 deletions(-) create mode 100644 packages/runtime-core/src/helpers/refMacros.ts create mode 100644 test-dts/refMacros.test-d.ts diff --git a/packages/runtime-core/src/helpers/refMacros.ts b/packages/runtime-core/src/helpers/refMacros.ts new file mode 100644 index 00000000..4c62441d --- /dev/null +++ b/packages/runtime-core/src/helpers/refMacros.ts @@ -0,0 +1,21 @@ +import { Ref, UnwrapRef, ShallowUnwrapRef, ComputedRef } from '@vue/reactivity' + +export function $ref(arg: T | Ref): UnwrapRef +export function $ref() {} + +declare const ComputedRefMarker: unique symbol +type ComputedRefValue = T & { [ComputedRefMarker]?: any } + +export function $computed(getter: () => T): ComputedRefValue +export function $computed() {} + +export function $fromRefs(source: T): ShallowUnwrapRef +export function $fromRefs() { + return null as any +} + +export function $raw(value: ComputedRefValue): ComputedRef +export function $raw(value: T): Ref +export function $raw() { + return null as any +} diff --git a/packages/runtime-core/src/index.ts b/packages/runtime-core/src/index.ts index 3249f3a4..79784acc 100644 --- a/packages/runtime-core/src/index.ts +++ b/packages/runtime-core/src/index.ts @@ -53,20 +53,19 @@ export { provide, inject } from './apiInject' export { nextTick } from './scheduler' export { defineComponent } from './apiDefineComponent' export { defineAsyncComponent } from './apiAsyncComponent' +export { useAttrs, useSlots } from './apiSetupHelpers' //