emitter报错:
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<ValidateFunc>): void', gave the following error.
Argument of type '(func: ValidateFunc) => void' is not assignable to parameter of type 'Handler<ValidateFunc>'.
Types of parameters 'func' and 'event' are incompatible.
Type 'ValidateFunc | undefined' is not assignable to type 'ValidateFunc'.
Type 'undefined' is not assignable to type 'ValidateFunc'.Vetur(2769)
代码如下:
const callback = (func: ValidateFunc) => {
funcArr.push(func)
}
emitter.on('form-item-created', callback)
onUnmounted(() => {
emitter.off('form-item-created', callback)
})
如果写成const callback = (func: any) ,就不会报错,为什么这个类型推断会产生错误?我看了emitter的EventType是any,没搞明白