diff --git a/packages-private/dts-test/ref.test-d.ts b/packages-private/dts-test/ref.test-d.ts index 89b80a70fb5..2a2ac1495e6 100644 --- a/packages-private/dts-test/ref.test-d.ts +++ b/packages-private/dts-test/ref.test-d.ts @@ -4,6 +4,7 @@ import { type MaybeRefOrGetter, type Ref, type ShallowRef, + type TemplateRef, type ToRefs, type WritableComputedRef, computed, @@ -535,7 +536,7 @@ expectType(toValue(unref2)) // useTemplateRef const tRef = useTemplateRef('foo') -expectType>>(tRef) +expectType>(tRef) const tRef2 = useTemplateRef('bar') -expectType>>(tRef2) +expectType>(tRef2) diff --git a/packages/runtime-core/src/helpers/useTemplateRef.ts b/packages/runtime-core/src/helpers/useTemplateRef.ts index 4cb10ea8139..09d34840dd8 100644 --- a/packages/runtime-core/src/helpers/useTemplateRef.ts +++ b/packages/runtime-core/src/helpers/useTemplateRef.ts @@ -5,9 +5,11 @@ import { EMPTY_OBJ } from '@vue/shared' export const knownTemplateRefs: WeakSet = new WeakSet() +export type TemplateRef = Readonly> + export function useTemplateRef( key: Keys, -): Readonly> { +): TemplateRef { const i = getCurrentInstance() const r = shallowRef(null) if (i) { diff --git a/packages/runtime-core/src/index.ts b/packages/runtime-core/src/index.ts index 3871167b3ee..9910f82102b 100644 --- a/packages/runtime-core/src/index.ts +++ b/packages/runtime-core/src/index.ts @@ -64,7 +64,7 @@ export { defineComponent } from './apiDefineComponent' export { defineAsyncComponent } from './apiAsyncComponent' export { useAttrs, useSlots } from './apiSetupHelpers' export { useModel } from './helpers/useModel' -export { useTemplateRef } from './helpers/useTemplateRef' +export { useTemplateRef, type TemplateRef } from './helpers/useTemplateRef' export { useId } from './helpers/useId' export { hydrateOnIdle,