Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Method cannot be called on any member of intersection type intersection - Flow|React|Immutable

Declared props:

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

Assigning variables from props using destructuring:

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

user variable is typeof Map (immutable.js map). Have to use .toJS() to change it into an object. But then the flow error/warning appears:

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

Was trying to handle it myself, failed miserably.

Any help highly appreciated!

like image 960
Han Zoe Avatar asked Nov 07 '22 18:11

Han Zoe


1 Answers

It was fixed with:

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

like image 119
Han Zoe Avatar answered Nov 14 '22 23:11

Han Zoe