How to get the EmitsType of components in TypeScript ? #6116
-
There is no type prompt for calling component functions through Ref. after looking at the generic types in @vue/runtime-core, how can I extract types similar to objectemitsoptions in definecomponent? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
I tried many times through instancetype, but it didn't work |
Beta Was this translation helpful? Give feedback.
-
One parameter type in the generic definecomponent is emitsoptions. It can be seen from the source code. The key is how to extract this type |
Beta Was this translation helpful? Give feedback.
-
Extracting a generic argument in TypeScript typically looks like this (I haven't tested): import type { DefineComponent } from 'vue'
export type ExtractEmits<T> = T extends DefineComponent<any, any, any, any, any, any, any, infer U> ? U : unknown Perhaps #2179 can inspire you, too. |
Beta Was this translation helpful? Give feedback.
Extracting a generic argument in TypeScript typically looks like this (I haven't tested):
Perhaps #2179 can inspire you, too.