Skip to content

BUG | useElementSize | TS error if templateRef target uses emit #5072

@kubajmarek

Description

@kubajmarek

Describe the bug

The bug is simple, if the useElementSize is used with templateRef that targets Vue Component, and that component emits, then TypeScript will fail:

types of property '$emit' are incompatible.
                  Type '(event: "mounted", ...args: any[]) => void' is not assignable to type '(event: string, ...args: any[]) => void'.
                    Types of parameters 'event' and 'event' are incompatible.
                      Type 'string' is not assignable to type '"mounted"'.

This happens regardless if emit is consumed by parent or not, and regardless of which defineEmits syntax we're using.

I've also found this issue with useFocusWithin, so all functions taking MaybeElement might be affected.

Reproduction

https://stackblitz.com/edit/stackblitz-starters-jqvqqvmh

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 20.19.1 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.8.2 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/bin/pnpm
  npmPackages:
    @vueuse/core: ^13.9.0 => 13.9.0 
    vue: ^3.5.22 => 3.5.22

Used Package Manager

npm

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions