-
-
Notifications
You must be signed in to change notification settings - Fork 425
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Cannot use InstanceType<typeof Comp<any>>>
on generic components
#3206
Comments
I aslo!!! use vue@3.3.4,vue-tsc@1.6.5. |
When using Another option is to use import MyComp from './MyComp.vue'
import type { ComponentExposed } from 'vue-component-type-helpers'
const el = ref<null | ComponentExposed<typeof MyComp<any>>>( null ) |
@varlamov88 Depends on how badly you need it, but I deconstructed the type into a new one based on |
I can confirm that |
This is my temporary solution, but it's not perfect😂. I'm looking forward to the official release of the final solution. import { type DefineComponent } from 'vue'
import MyComp from './MyComp.vue'
type ComponentInstance<T> = T extends new (...args: any[]) => infer R
? R
: T extends (...args: any[]) => infer R
? R extends { __ctx?: infer K }
? Exclude<K, void> extends { expose: (...args: infer K) => void }
? K[0] & InstanceType<DefineComponent>
: any
: any
: any
const el = ref<null | ComponentInstance<typeof MyComp<any>>>(null) |
bump - need this please |
@Bernard-Borg #3271, please be patient :) |
Hey guys, it's really blocking the use of generic components, any chance that it will be fixed soon? Thanks for the great tools btw :) |
Hey folks 👋 Could you please checkout #3536? Does it work for you? Note You should use |
Hey! how I'm supposed to do, when I want for example |
For some reason, I am getting |
I have the same problem. Why this issue is closed? |
Hello, I am still facing this issue and the fix is not really clear. |
Install |
Edit: I removed my original comment since I see that the PR so1ve linked fixes the issue, and I got it to work! I think what happened is that after manually updating the package I didn't properly reload the Volar project. For anyone else who is still getting this issue, I would check that node_modules/vue-component-type-helpers is in fact on 1.8.27, since mine wasn't after I updated Vue to 3.4 (maybe because of my package-lock? not sure). Thanks for the fix! |
@so1ve I have wrong Vuelidate (https://vuelidate-next.netlify.app/#getting-started-1) type. It should be available without |
Looking forward to your update |
I've just tried this solution and for some reason Typescript were complaning about import { type DefineComponent } from 'vue'
export type GenericComponentInstance<T> = T extends new (...args: any[]) => infer R
? R
: T extends (...args: any[]) => infer R
? R extends { __ctx?: infer K }
? Exclude<K, void> extends { expose: (...args: infer Y) => void }
? Y[0] & InstanceType<DefineComponent>
: any
: any
: any; |
|
|
Am I not running into the same issue though? IntstanceType not working with components that have a generic? |
For anybody checking this issue in the future, it's worth noting that this URL is incorrect. The correct URL is https://github.com/vuejs/language-tools/tree/master/packages/component-type-helpers |
Since the push of adding generic components on Vue 3.3.0, we don't seem able to get the
InstanceType
akapublic instance
anymore.The text was updated successfully, but these errors were encountered: