I found a weird error message in Vue 3 emit function when i use it with TypeScript. example code to reproduce:
export default defineComponent({
emits: {
emit1: (payload: number) => payload,
emit2: (payload: string) => payload
},
methods: {
...
}
}
when i try to call the emit1 like the following, it compiles without an error:
this.$emit("emit1", 1);
but if i do the following there is weird error:
this.$emit("emit1", "test");
TS2769: No overload matches this call.
The last overload gave the following error.
Argument of type '"emit1"' is not assignable to parameter of type '"emit2"'.
if i change the order of the emit functions like so:
export default defineComponent({
emits: {
emit2: (payload: string) => payload,
emit1: (payload: number) => payload
},
methods: {
...
}
}
Of course also a error appears, but this one make more sense at least:
TS2769: No overload matches this call.
The last overload gave the following error.
Argument of type 'boolean' is not assignable to parameter of type 'number'.
since the function name is defined in both cases the error message #1 makes no sense but #2 does.
My Questions:
- why does the order of the functions has an impact on the error message?
- should / can this be fixed in vue so that the error makes sense in both cases? Mybe this is also a issue with TypeScript itself?