声明的道具:
type IProps = {
user: ?Map<string, any> & Record<IUser>,
};
使用解构从 props 赋值变量:
const { user } = this.props;
const { name, surname } = user.toJS(); // <---- flow doesn't like this line
user
变量是 typeof Map (不可变.js map(。必须使用.toJS()
将其更改为对象。但随后出现流错误/警告:
Flow: Call of method .toJS().
Method cannot be called on any member of intersection type intersection.
试图自己处理它,惨败了。
任何帮助都非常感谢!
它已修复为:
const { name, surname } = user instanceof Map ? user.toJS() : {};