I have created an emit within my
<script setup lang="ts">
and I want to pass that emit to my composable so it can handle the emitting process.
However, I need to ensure that the received parameter is properly casted (as using any
is not ideal, and it results in emit
not being recognized as a function).
The code snippet below showcases this:
export type EmitType = {
'search': [value: string]
}
To initialize the composable, I would do something like this:
<script setup lang="ts">
const emit = defineEmits<EmitType>();
useComposable(emit);
</script>
Then, I use EmitType
to cast my emit
parameter:
const useMyComposable(emit: EmitType) {
emit('search', 'a string');
}
Despite this, when I call emit()
within the composable, I encounter the following error:
This expression is not callable.
Type 'EmitType' has no call signatures.
This issue arises due to potential differences in the type assigned by defineEmits
.
In summary, my question is:
What is the correct way to define emit
within my composable to eliminate errors, avoid using any
as a type, and enable proper intellisense?