如何告诉打字稿有关另一个模块“混入”的功能?

问题描述

我有这种情况:

// Application.ts
import MicroEvent from 'microevent-github'

class Application {
  // stuff...
  something() {
    // It is also saying "trigger" is undefined,// but it IS defined,MicroEvent defined it.
    this.trigger('foo')
  }
}

// get the `bind`,`unbind`,and other methods from MicroEvent
MicroEvent.mixin(Application)

const app = new Application()

const handleFoo = () => console.log('foo')

// try to use them,get the squiggly errors saying
// `bind` doesn't exist on Application,etc.
application.bind('foo',handleFoo)
application.unbind('foo',handleFoo)

我已经将MicroEvent“混入”到我的应用程序中,这向对象添加了一些方法。但是,VSCode抱怨bindunbind在Application实例上不存在...但是确实存在,我如何告诉打字稿接受这一点?

添加此项无效:

type Application = {
  bind: (eventType: string,callback: () => void) => void
  unbind: (eventType: string,callback: () => void) => void
  trigger: (eventType: string) => void
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)