Corrected and improved docs on type definitions for Custom Elements. #3073
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The doc was incorrect for two reasons:
GlobalComponents
need to be the Vue component types, not the custom element types, or the custom elements will not be type checked in Vue templates.A few questions:
DefineCustomElement
type helper invue
?Having examples/helpers/tests could prevent the docs from being incorrect.
There's a conversation in
#typescript
in Vue's Discord where we chatted about and worked on this.The conversation includes the idea of updating
vue-tsc
so that Custom Element type definitions can instead be added toIntrinsicElementAttributes
, which I tried at first but it currently does not work. Only built-in elements onIntrinsicElementAttributes
work, so I resorted to usingGlobalComponents
with the$props
and$emit
hacks which results in element ref types exposing non-existent$props
and$emit
properties to the user.So one more question is:
vue-tsc
? Or do we wait untilvue-tsc
can be updated so that hyphenated element names can successully be added toIntrinsicElementAttributes
, and update these docs to show the proper way of defining element types withIntrinsicElementAttributes
? cc @KazariEX @johnsoncodehk