Javascript 在动态构建的对象上使用流类型

Javascript 在动态构建的对象上使用流类型,javascript,flowtype,Javascript,Flowtype,我开始在javascript代码中使用流类型检查器。我倾向于使用javascript实现相当多的功能,并且我经常以友好的方式构建API 例如,这在我的代码中非常常见: const levels = [`error`, `warn`, `log`, `info`, `debug`]; const API = Object.create(null); API.flush = flush.bind(API, false); // Here I'm attaching the rest

我开始在javascript代码中使用流类型检查器。我倾向于使用javascript实现相当多的功能,并且我经常以友好的方式构建API

例如,这在我的代码中非常常见:

  const levels = [`error`, `warn`, `log`, `info`, `debug`];
  const API = Object.create(null);
  API.flush = flush.bind(API, false);
  // Here I'm attaching the rest of the methods to the api
  levels.reduce(
        (api, name, lvl) => {
          api[name] = handleLogMessage.bind(api, name, lvl);
          return api;
        }, API);
现在,如果我想用流来覆盖这个接口,我会尝试这样做:

type iTracer = {
    flush(): void,
    warn(): void
};
但是我得到了几个错误,比如这个:'Property未在可能为null的值null'中找到或更奇怪:
协变属性
warn
与计算属性/元素赋值中的逆变用法不兼容

flow难道不应该理解javascript的动态特性并与之一起流动吗?老实说,这大大降低了我的工作效率,而不是提高了我的工作效率


如果您能帮上忙,我们将不胜感激

我没有时间来整理答案,但这有帮助吗?