-
-
Notifications
You must be signed in to change notification settings - Fork 414
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Attribute inheritance in TSX #3496
Comments
Duplicate of #3301 |
Ah, I think this issue is more descriptive. |
Is there any way to fix this problem? |
@PurpleTape Maybe we need to fix types in vue core |
It’s 2024 and this problem hasn’t been fixed yet? |
Honestly you should add some types to props. |
@so1ve who are you replying to? This is part of the standard Vue functionality so it's not reasonable to expect someone to create a workaround just for the editor integration. And also it's not always possible when relying on third-party components. And also there are PRs (including yours) that seem to try to address it: |
Those PRs are trying to address the usage of SFC, not TSX. IMO TSX should report those issues since there is no |
Well, the Vue behavior is to treat unknown attributes as "fallthrough attributes". The VButton can't know up-front what one might want to pass as a fall-through attribute so it can't define them up-front.
Maybe you want to handle SFC and TSX separately (I have no opinion on that) but this is not a TSX-specific problem. It's equally valid for SFC: That said, I don't like this feature of Vue very much as if the Vue language tools would follow that logic (fix this issue basically) then mistyped prop names would no longer be reported as invalid and then there would be another group of people who would complain about that... |
In my imagination
+1 :) |
Here's a temporary workaround, guys. It might not be the most elegant solution, but it's effective. import 'vue';
type EventHandler = (...args: any[]) => void;
declare module 'vue' {
interface ComponentCustomProps {
id?: string;
role?: string;
tabindex?: number;
onClick?: EventHandler;
onTouchend?: EventHandler;
onTouchmove?: EventHandler;
onTouchstart?: EventHandler;
onTouchcancel?: EventHandler;
onTouchmovePassive?: EventHandler;
onTouchstartPassive?: EventHandler;
}
interface HTMLAttributes {
onTouchmovePassive?: EventHandler;
onTouchstartPassive?: EventHandler;
onClickCapture?: EventHandler;
}
} You can find more context here at vant. |
Hello! I encountered the following situation: for vue components that wrap native html elements, all properties not specified in
props
automatically fall intoattrs
and can be applied to a native html element. However, volar indicates a typescript error, since properties not specified inprops
are missing from the type.The problem occurs in the following cases:
Thus, the attributes are passed as intended, but the IDE displays a type error
Example:
Info:
TypeScript Vue Plugin (Volar) v1.8.8
How can I eliminate the display of such errors?
Thanks!
The text was updated successfully, but these errors were encountered: