Typing ref
of a generic component instance
#10380
Unanswered
mybearworld
asked this question in
Help/Questions
Replies: 3 comments 2 replies
-
<script lang="ts" setup generic="T = object">
const props = defineProps<{
value?: Partial<T>[];
}>();
const emit = defineEmits<{
(evt: 'change', val?: Partial<T>[]): void;
}>();
</script> <script lang="ts" setup>
import type { ComponentProps } from 'vue-component-type-helpers';
import Comp from './Comp.vue';
const onChange: ComponentProps<typeof Comp>['onChange'] = (val) => {
// ...
};
</script> |
Beta Was this translation helpful? Give feedback.
1 reply
-
Does anyone know how to do this? |
Beta Was this translation helpful? Give feedback.
0 replies
-
Also interested in the answer to this as I've been unable to get the correct typing despite much experimentation... Update: I don't think this is possible so likely requires an issue raising |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
To type a
ref
to a component instance ofF
in Typescript, you'd normally doref<InstanceType<typeof F> | null>(null)
. However, this type errors: whenComponent
is a generic component:This also happens when you do specify the generic type, like
ref<InstanceType<typeof F<number>> | null>(null)
, with this error:This is the
F.vue
component:I'm kind of stuck here. How do you type a
ref
to an instance of a generic component?Beta Was this translation helpful? Give feedback.
All reactions