Skip to content

Commit 8e141e5

Browse files
authored
feat(useCurrentElement): try to infer type from $el (#4202)
1 parent 6b58430 commit 8e141e5

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

packages/core/useCurrentElement/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
// eslint-disable-next-line no-restricted-imports
22
import { getCurrentInstance, onMounted, onUpdated } from 'vue-demi'
3-
import { computedWithControl } from '@vueuse/shared'
3+
import { type IsAny, computedWithControl } from '@vueuse/shared'
44
import type { MaybeElement, MaybeElementRef, VueInstance } from '../unrefElement'
55
import { unrefElement } from '../unrefElement'
66

77
export function useCurrentElement<
88
T extends MaybeElement = MaybeElement,
99
R extends VueInstance = VueInstance,
10+
E extends MaybeElement = MaybeElement extends T ? IsAny<R['$el']> extends false ? R['$el'] : T : T,
1011
>(
1112
rootComponent?: MaybeElementRef<R>,
1213
) {
1314
const vm = getCurrentInstance()!
1415
const currentElement = computedWithControl(
1516
() => null,
16-
() => (rootComponent ? unrefElement(rootComponent) : vm.proxy!.$el) as T,
17+
() => (rootComponent ? unrefElement(rootComponent) : vm.proxy!.$el) as E,
1718
)
1819

1920
onUpdated(currentElement.trigger)

0 commit comments

Comments
 (0)