[Feature Request] infer v-if
type narrowing on the @event
#1249
Labels
enhancement
New feature or request
from #146
Goal
When we are writing complex templates we often have
v-if
that will do type narrowing on for the children, those type narrowings are really useful and is a pain to need to cast inside of the@event
possibly causing bugs down the line (if av-if
is changed, etc)As you can see, you need to cast it to be able to work, which is a pain, good luck inferring types correctly from third-party or nested types...
Solution
To solve this
@events
functions should have the same type narrowing than the render component.This makes sense in vue because events are not fired/emitted after a component is disposed (which happens on v-if=false).
Philosophy
At first sight we can blame this to typescript, because variable can change to other types, but in
vue
a component is not render if the v-if condition is false, making the scope of the event pretty much the scope after thev-if
(only when using prop function that might introduce a error)Implementation
We can implement this by following this 3 rules:
Example:
playground
The text was updated successfully, but these errors were encountered: