Repository navigation
Typing when using the .attr when binding attributes on customElemen
#5973
Replies: 1 comment
|
Your understanding of the runtime behavior is correct, but the current template type checker does not appear to model attributes and DOM properties as two separate type domains. At runtime, Vue behaves as documented:
DOM attributes are serialized as strings, while a custom element property can hold values such as The current Source: So, as things stand, declaring two different types for the same custom-element key and having the modifier select between them does not seem expressible. This looks like a missing typing feature (or a language-tools bug), rather than an ESLint problem. A narrow workaround is to serialize attribute values explicitly and limit the type escape to that binding: <my-element
:value.prop="numericValue"
:value.attr="String(numericValue) as any"
/>For a A minimal issue containing the custom-element declaration plus one
|
Uh oh!
There was an error while loading. Please reload this page.
I am having some struggles when type checking a customElement that has different types between the attribute (string) and the property which is different (eg. number or Date).
Apparently the types related to the properties cannot differe from the attributes. Which if I am not mistaken when using the
.attrmodifier the possible type should be only a subset of strings.There is the caveat of not having the modifier(.attr/.prop), which endup with checking the property type if the name exists or apply a string only.
Currently I am having to shortcut the check by forcing eslint to skip the entire attribute.
What do you think?
All reactions