import mitt from 'mitt'
export const emitter = mitt()
export default defineComponent({
setup(props, context) {
const callback = (text: string) => {
console.log(text)
}
emitter.on('form-item-created', callback)
onUnmounted(() => {
emitter.off('form-item-created', callback)
})
}
})
TS2769: No overload matches this call.
Overload 1 of 2, '(type: "*", handler: WildcardHandler): void', gave the following error.
Argument of type '"form-item-created"' is not assignable to parameter of type '"*"'.
Overload 2 of 2, '(type: string | symbol, handler: Handler<string>): void', gave the following error.
Argument of type '(text: string) => void' is not assignable to parameter of type 'Handler<string>'.
Types of parameters 'text' and 'event' are incompatible.
Type 'string | undefined' is not assignable to type 'string'.
Type 'undefined' is not assignable to type 'string'.
28 | }
29 |
> 30 | emitter.on('form-item-created', callback)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
31 |
32 | onUnmounted(() => {
33 | emitter.off('form-item-created', callback)
ERROR in src/components/Form/index.vue:33:7
TS2769: No overload matches this call.
Overload 1 of 2, '(type: "*", handler: WildcardHandler): void', gave the following error.
Argument of type '"form-item-created"' is not assignable to parameter of type '"*"'.
Overload 2 of 2, '(type: string | symbol, handler: Handler<string>): void', gave the following error.
Argument of type '(text: string) => void' is not assignable to parameter of type 'Handler<string>'.
31 |
32 | onUnmounted(() => {
> 33 | emitter.off('form-item-created', callback)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
34 | })
35 |
36 | return {
看了很多网上的,没看到有效的解决方案,mitt也是2.1.0的