feat: add unknown on props class
in public props
#5539
Closed
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.
Hello 👋
Trying to play around with
class
inheritance with components, I experimented something a bit un-documented from VueJS: even if a propsclass
is defined, theclass
compilation (transformining an object with conditions to a string) will still happen.Here is a simple reproduction: Vue Playground.
This behavior is quite interesting as it allows the child component to get the class without having the need to use
defineOptions({ inheritAttrs: false })
anduseAttrs
. The typing on theclass
is therefore better, even if the user can in theory put any kind of type likeboolean
for theclass
props, not resulting in a type error, even if theclass
will be a string after VueJS compilation.I would like to propose a change in the typing tools in this repository to allow this behavior from a typing perspective. The
vue-tsc
and language server are raising errors about the type of theclass
props being given to the child component, even if VueJS will always compile this props to a string.I'm trying to put the default type of
class
from VueJS which isunknown
: https://github.com/vuejs/core/blob/e60edc06f29b32c8f3a44d0ab3558a0569515e8f/packages/runtime-core/src/component.ts#L185, but only on the public interface of a component, as it will be astring
inside.I think enforcing the prop
class
to always be a string inside the component in itself needs to be done in the VueJScore
repository, but I'm not sure.This is clearly a proposal, happy to discuss this but I find the behavior quite useful and would like to push more usage of this in the VueJS community.