Subscribe on changes!

$el is typed as any

avatar
Mar 18th 2023

Vue version

3

Link to minimal reproduction

https://sfc.vuejs.org/#eNpVUcFOwzAM/RUTIXWTWCquWzeE4MAfcMlltO7WKXGixNmQqv47TjcmOLXP7/n52RnVawj6nFGtVZPaOASGhJzDztDggo8MI0TsYYI+egeVSCtDhlpPicGlA2wLv6g+0FoPnz7a7qFaGmrqq50YCWB0we4ZBQE0x+fdOM7N09TUgubqQCEznFfOd2i3RglvlFBNfe9WT+qaauX2QZ+SJ8k9lm5zI5JRa5grpSZpCzbqyBzSuq5T35ZtT0n7eKjlT8dMPDjUmNzqK/pLwijGRhWLydAkI8uJOMmk+0U67AfCNy+YkPjfdTZlYfyelaLbZzt//+oXc8BWYGbsfuN2vs2usMv7AhzlLSIBH4ekH9G+aH8hjO83pYwqMol5zbrcqOkHn+mgyA==

Steps to reproduce

this.$el has the any type

What is expected?

this.$el has the Node | undefined type

What is actually happening?

this.$el has the any type

System Info

No response

Any additional comments?

$el is defined at runtime-core/src/componentPublicInstance.ts line 197

avatar
Mar 21st 2023

I think it's indeed any. Or, to make it safer, unknown. Vue 3 didn't require element to meet specified interface because implementation of node operations is specified outside of runtime-core

https://github.com/vuejs/core/blob/main/packages/runtime-dom/src/nodeOps.ts

The $el can be whatever you want if you are in other runtime.

avatar
Mar 21st 2023

I agree with @mmis1000 , I also think it should be any. You must know that Vue supports custom renderers, which makes the content rendered by components not necessarily standard dom elements

avatar
Mar 21st 2023

Maybe adjust the documentation at https://vuejs.org/api/component-instance.html#el to reflect that? It states that $el is Node | undefined.

avatar
Mar 21st 2023

Wondering if it is possible to left it as a blank interface and argument in runtime-dom.

Like what express.js does

https://stackoverflow.com/questions/37377731/extend-express-request-object-using-typescript

In this way, if you don't have runtime-dom installed. It is {}. Or if you have, it will suddenly be Node