// @flow
import type {RecordOf} from 'immutable';
function foo<T: {[string]: string}>(state: RecordOf<T>) {
for (let [key, value] of state) {
console.log(key, value);
}
}
在上面的代码中,for...of
循环导致流类型错误:
$Iterable. Could not decide which case to select intersection type
。
我认为这是因为immutable.js将RecordOf
定义为type RecordOf<Values: Object> = RecordInstance<Values> & Values;
。但是,RecordInstance
未导出,因此如何告知流state
确实是RecordInstance
并且可以像这样迭代?