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

Han*_*Zoe 5 javascript debugging reactjs flowtype immutable.js

声明道具:

type IProps = {
  user: ?Map<string, any> & Record<IUser>,
};
Run Code Online (Sandbox Code Playgroud)

使用解构从props分配变量:

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

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

Flow: Call of method .toJS().
Method cannot be called on any member of intersection type intersection.
Run Code Online (Sandbox Code Playgroud)

试图自己处理它,失败了.

任何帮助高度赞赏!

小智 1

它被修复为:

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