mirror of https://github.com/vuejs/core.git
feat(types): add type TemplateRef (#12645)
* feat(types): add type TemplateRef * chore: simplify Co-authored-by: jh-leong <jh.leong@outlook.com> --------- Co-authored-by: jh-leong <jh.leong@outlook.com>
This commit is contained in:
parent
d48937fb95
commit
636a8619f0
|
@ -4,6 +4,7 @@ import {
|
||||||
type MaybeRefOrGetter,
|
type MaybeRefOrGetter,
|
||||||
type Ref,
|
type Ref,
|
||||||
type ShallowRef,
|
type ShallowRef,
|
||||||
|
type TemplateRef,
|
||||||
type ToRefs,
|
type ToRefs,
|
||||||
type WritableComputedRef,
|
type WritableComputedRef,
|
||||||
computed,
|
computed,
|
||||||
|
@ -535,7 +536,7 @@ expectType<string>(toValue(unref2))
|
||||||
|
|
||||||
// useTemplateRef
|
// useTemplateRef
|
||||||
const tRef = useTemplateRef('foo')
|
const tRef = useTemplateRef('foo')
|
||||||
expectType<Readonly<ShallowRef<unknown>>>(tRef)
|
expectType<TemplateRef>(tRef)
|
||||||
|
|
||||||
const tRef2 = useTemplateRef<HTMLElement>('bar')
|
const tRef2 = useTemplateRef<HTMLElement>('bar')
|
||||||
expectType<Readonly<ShallowRef<HTMLElement | null>>>(tRef2)
|
expectType<TemplateRef<HTMLElement>>(tRef2)
|
||||||
|
|
|
@ -5,9 +5,11 @@ import { EMPTY_OBJ } from '@vue/shared'
|
||||||
|
|
||||||
export const knownTemplateRefs: WeakSet<ShallowRef> = new WeakSet()
|
export const knownTemplateRefs: WeakSet<ShallowRef> = new WeakSet()
|
||||||
|
|
||||||
|
export type TemplateRef<T = unknown> = Readonly<ShallowRef<T | null>>
|
||||||
|
|
||||||
export function useTemplateRef<T = unknown, Keys extends string = string>(
|
export function useTemplateRef<T = unknown, Keys extends string = string>(
|
||||||
key: Keys,
|
key: Keys,
|
||||||
): Readonly<ShallowRef<T | null>> {
|
): TemplateRef<T> {
|
||||||
const i = getCurrentInstance()
|
const i = getCurrentInstance()
|
||||||
const r = shallowRef(null)
|
const r = shallowRef(null)
|
||||||
if (i) {
|
if (i) {
|
||||||
|
|
|
@ -64,7 +64,7 @@ export { defineComponent } from './apiDefineComponent'
|
||||||
export { defineAsyncComponent } from './apiAsyncComponent'
|
export { defineAsyncComponent } from './apiAsyncComponent'
|
||||||
export { useAttrs, useSlots } from './apiSetupHelpers'
|
export { useAttrs, useSlots } from './apiSetupHelpers'
|
||||||
export { useModel } from './helpers/useModel'
|
export { useModel } from './helpers/useModel'
|
||||||
export { useTemplateRef } from './helpers/useTemplateRef'
|
export { useTemplateRef, type TemplateRef } from './helpers/useTemplateRef'
|
||||||
export { useId } from './helpers/useId'
|
export { useId } from './helpers/useId'
|
||||||
export {
|
export {
|
||||||
hydrateOnIdle,
|
hydrateOnIdle,
|
||||||
|
|
Loading…
Reference in New Issue