声明道具:
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.
我自己试图处理它,悲惨地失败了。
任何帮助都非常感谢!
答案 0 :(得分:1)
修复了:
const { name, surname } = user instanceof Map ? user.toJS() : {};