请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

正在回答 回答被采纳积分+3

1回答

张轩 2020-10-01 22:07:08

同学你好 请问你的 callback 是怎样定义的,请把代码贴一下,mitt 的定义文件在我当时录课之后有了一小部分的更新,有可能会出现类型错误,可以参考这个常见问题 http://coding.imooc.com/learn/questiondetail/206736.html

0 回复 有任何疑惑可以回复我~
  • Linx #1
    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,没搞明白
    回复 有任何疑惑可以回复我~ 2020-10-10 23:19:23
  • 求解
    const callback = (func?: ValidateFunc) => {
          funcArr.push(func)
        }
    也会爆错
    回复 有任何疑惑可以回复我~ 2020-10-13 18:55:30
  • const childCallback: Handler<ValidateFunc> = (func) => {
          if (func) {
            validateFuncList.push(func);
          }
        };
        emitter.on('form-item-created', childCallback);
    回复 有任何疑惑可以回复我~ 2020-10-14 10:42:15
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信