Event name from variable

I was wondering if there was a way of emitting an event whose name comes from a variable. For instance:
const emit = defineEmits<{
close: void[]
open: void[]
}>()
const eventName = ref<'close' | 'open'>('close')
emit(eventName.value) // ts error No overload matches this call.
const emit = defineEmits<{
close: void[]
open: void[]
}>()
const eventName = ref<'close' | 'open'>('close')
emit(eventName.value) // ts error No overload matches this call.
2 Replies
Aleksandar Brkić
Aleksandar BrkićOP8mo ago
the above fires the correct event, just wondering how to get rid of that ts error
Single
Single8mo ago
const emit = defineEmits<{
(e: 'close' | 'open'): void
}>()
const eventName = ref<'close' | 'open'>('close')
emit(eventName.value)
const emit = defineEmits<{
(e: 'close' | 'open'): void
}>()
const eventName = ref<'close' | 'open'>('close')
emit(eventName.value)
Want results from more Discord servers?
Add your server