方法不能在交叉类型交集的任何成员上调用 - Flow | React | Immutable

时间:2017-07-31 11:26:06

标签: javascript reactjs debugging flowtype immutable.js

声明道具:

type IProps = {
  user: ?Map<string, any> & Record<IUser>,
};

使用解构从道具中分配变量:

const { user } = this.props;
const { name, surname } = user.toJS();   // <---- flow doesn't like this line

user变量是typeof Map(immutable.js map)。必须使用.toJS()将其更改为对象。但随后出现流量错误/警告:

Flow: Call of method .toJS().
Method cannot be called on any member of intersection type intersection.

我自己试图处理它,悲惨地失败了。

任何帮助都非常感谢!

1 个答案:

答案 0 :(得分:1)

修复了:

const { name, surname } = user instanceof Map ? user.toJS() : {};