Skip to content

Commit

Permalink
fix(unrefElement): improve types (#1409)
Browse files Browse the repository at this point in the history
  • Loading branch information
okxiaoliang4 committed Mar 15, 2022
1 parent de14228 commit 3e19431
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/core/unrefElement/index.ts
Expand Up @@ -3,14 +3,17 @@ import { unref } from 'vue-demi'
import type { MaybeRef } from '@vueuse/shared'

export type VueInstance = ComponentPublicInstance
export type MaybeElementRef = MaybeRef<HTMLElement | SVGElement | VueInstance | undefined | null>
export type MaybeElementRef<T extends MaybeElement = MaybeElement> = MaybeRef<T>
export type MaybeElement = HTMLElement | SVGElement | VueInstance | undefined | null

export type UnRefElementReturn<T extends MaybeElement = MaybeElement> = T extends VueInstance ? Exclude<MaybeElement, VueInstance> : T | undefined

/**
* Get the dom element of a ref of element or Vue component instance
*
* @param elRef
*/
export function unrefElement(elRef: MaybeElementRef): HTMLElement | SVGElement | undefined {
export function unrefElement<T extends MaybeElement>(elRef: MaybeElementRef<T>): UnRefElementReturn<T> {
const plain = unref(elRef)
return (plain as VueInstance)?.$el ?? plain
}

0 comments on commit 3e19431

Please sign in to comment.