【发布时间】:2016-12-15 23:04:58
【问题描述】:
我目前正在比较 Google Closure Compiler 和 Flow 静态类型检查器的表现力。我知道如何在 Closure 中但在 Flow 中不知道的一件事是表达一组具有相同类型的命名对象。在闭包中可以使用the @enum annotation。
/** @enum {function(number):number} */
const unaryFunctions = {
sin: Math.sin,
cos: Math.cos,
square: function(x) { return x*x; },
};
有没有办法使用 Flow 来做这样的事情?我想我可以使用 ES6 字典而不是普通对象,但是如果交叉编译到 ES5 会产生相当大的开销。我认为像这样的结构看起来很惯用,所以我很惊讶我在文档中找不到匹配的类型描述。
【问题讨论】:
标签: javascript dictionary types flowtype