-
-
Notifications
You must be signed in to change notification settings - Fork 594
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
Cross file template type checking - check that components are passed props with the correct types #1596
Comments
Looks good for Vue 2. We can reuse component props type in Vue 3 as |
My preferred syntax would be close to the native props: {
userList: {
type: Array as PropType<User[]>,
default: () => []
},
category: {
type: String as PropType<MY_ENUM>,
required: true
}
} Having to define the prop types outside of the actual place you write the props, it would be less ideal in my opinion. Also anything that stays closest to regular Vue syntax seems best for me. 😉 |
@mesqueeb We are talking about auto generated (probably virtual) type declaration for Vetur which the end users won't see / edit. I believe a simple interface type derived from Vue component's props option is enough to utlize it in template type checking. |
@ktsn Aha! I had originally posted my question in the VTI feedback thread, but was redirected here... My question was: "Will it be possible for VTI to catch TypeScript type errors by annotating types via eg. |
Yes, it will be possible! We already have rough idea to achieve it. |
When one has a Vue file:
Such templates should show error:
Currently we have:
I'm wondering if we could do something like this. For each imported Vue component, generate its corresponding type definition such as:
Then the virtual file with this content would complain:
It should be easy to translate the props interface:
required: false
is specified, translate tomsg?: type
. Otherwise translate tomsg: type
type
is inferred from constructor types. For exampleString -> string
. If uninferrable, useany
.@ktsn What do you think?
The text was updated successfully, but these errors were encountered: