-
-
Notifications
You must be signed in to change notification settings - Fork 421
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
Detect unknown/undefined prop usage #1077
Comments
This is intentional behavior as this is often used in css selectors. I'll explore add a option in vueCompilerOptions to change this behavior. |
@johnsoncodehk thanks |
I also think it is great to have this feature. |
But it seems that vue always treat attribute |
It may be more appropriate to handle this case by giving a warning rather than an error. |
@johnsoncodehk Do you have any plan for adding that? Maybe we can check with |
In 0.36, custom / unknown attrs types behavior handle responsibility will transfer to developer.
<template>
<div myprop="a">
</template> // env.d.ts
declare module '@vue/runtime-dom' {
interface HTMLAttributes {
myprop: string
}
}
export { }
// env.d.ts
// for native html elements
declare module '@vue/runtime-dom' {
interface HTMLAttributes {
[key: string]: any
}
interface SVGAttributes {
[key: string]: any
}
}
// for vue components
declare module '@vue/runtime-core' {
interface AllowedComponentProps {
[key: string]: any
}
}
export { } |
@johnsoncodehk Thankyou for mentioning that here. Suddenly today my Visual Studio Code started giving 'property does not exist on type' warnings for all the custom attributes starting with 'data-*' like this declare module '@vue/runtime-dom' { export { } |
@johnsoncodehk Since this change regarding unknown properties. I am also getting this error on a V-Calendar Components v-model value before this it was fine. I am newbie and don't have any idea how I can omit this warning. |
Hello. How to enable ignoring this case? |
This change is bonkers! How do volar check where this attribute that I passed on purpose ends up? Does it just "assumes" it is the root element of the template? But even that doesn't work properly. Vue has an attribute fallthrough on purpose and this change makes vue-tsc crash on basically every component where I use attribute fallthrough (which I use A LOT). This feature should be opt-in and not opt-out. How can I disable this? |
@ildan95 You can add the below listed code in your env.d.ts file and it will allow you to use the data-* and aria-* properties.
|
@johnsoncodehk your solution does not work for components. I cant even pass an id attribute to a component |
@Fuzzyma His solution has worked for me and now I am able to add any properties and Visual Studio Code dont show up any warnings for them just like earlier. Add this to your env.d.ts file in your Project Root Folder.
|
@lohchab I can't make it work on components LIke on native elements it works fine, but what about component attributes? I have VInput component which is just a wrapper around native input. SO i have to describe ALL native attributes in props to apply them? |
exactly. it might work for html elements but attribute fallthrough for components doesn't work at all |
I got you. Yes, you are right I can confirm its is not working. Its only working for HTML Elements. For a temporary workaround till the time there's a no solution to this my recommendation is that you switch your Volar Extension Version to the '0.35.2' and Restart the Visual Studio Code. |
Until this is fixed, the proper solution is to revert this feature or hide it behind a flag and release a new version because in the current state it's just plane broken |
You should use |
Thankyou @johnsoncodehk I can confirm adding this code to env.d.ts file has solved the unknown property problems for both HTML and Vue Component Elements. Keep up the good work. We all appreciate what you are doing on Volar! |
I agree that this type of strict linting should be opt-in, fallthrough attributes are a common use case with Vue and the default configuration of Volar should just work with the examples from the Vue docs. |
This isn't just about fallthrough either, as shown in #1383 this is causing errors for many completely standard HTML attributes directly on the elements. It seems unreasonable requiring people to add custom declaration files to avoid that |
Is it possible to make an option like mode="strict" to change default behavior? I mean, props existence check looks like an edge case than something default. Because everything that not described in props are custom attributes, that's vue default behavior |
It didn't work unfortunately as the project that I'm working on at the moment is using pure JavaScript without TypeScript, and the errors always appear. |
Thanks to this feature, I noticed that the Vuetify property names had been updated and was able to correct them. :)
For now, I use the following definition in import '@vue/runtime-core';
import '@vue/runtime-dom';
// for vue components
declare module '@vue/runtime-core' {
export interface AllowedComponentProps {
[key: string]: any;
}
}
// for native html elements
declare module '@vue/runtime-dom' {
export interface HTMLAttributes {
// allow any data-* attr
[key: `data${string}`]: string;
}
}
export {}; Complex libraries such as Vuetify do not always have all properties defined (especially if they are passed through), and users will end up having to disable the feature completely. |
In v0.36.1 this behavior is control by // tsconfig.json
{
"vueCompilerOptions": {
"experimentalSuppressUnknownJsxPropertyErrors": false
}
} If you see how volar hacking JSX types to ignore unknown prop errors, you may want to disable it. (This shouldn't be part of volar's control) |
Can you make this disabled by default instead? I still don't understand what the real point is, as this change breaks totally valid code all over the place for known attributes like all aria attributes. I'm sure there's good intentions here, but people (especially new users) will have no idea what is going on when their |
@TheDutchCoder Maybe there are some misunderstood, "SuppressUnknownJsxPropertyErrors" mean ignore unknown prop errors, I think you don't want disabled it by default. |
Okay I'll give it a spin later. Just to clarify: So regardless of the setting, these should never throw errors, which was the original issue. |
I can confirm that the update fixes all issues. The feature is now opt-in as described above. Thank you for the quick fix! |
As @TheDutchCoder said, <template>
<input aria-describedby="emailHelp">
<p id="emailHelp">aria help...</p>
</template> |
Fix by ba2835f. |
@johnsoncodehk If I disable Example: Edit: maybe this isn't released yet? |
@TheDutchCoder if you don't have the option set, it's on by default. Which means volar behaves as if this feature wasn't enabled at all (its a feature flag). Nothing else was changed afaik. |
This still doesn't solve anything. Setting this to |
I am unable to get this to work with the latest version. Can anyone confirm that this feature still works as expected? |
@IceBlizz6 You should use |
This is a proposal for enhancing vue-tsc
Example:
When running npx vue-tsc --noEmit i want it to detect that propThatDoesNotExist is not presently defined in myComponent.
This could produce a warning or error.
Feature like this currently exists in TS files.
When trying to edit fields that is not defined in some typescript class it will output:
Property 'xxx' does not exist on type 'MyClass'.
This would be very helpful for Vue developers when renaming props or performs refactoring or git rebases as looking through the code manually can be tedious.
The text was updated successfully, but these errors were encountered: