You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// `state` is obtained from redux store// `state.user` is an immutable object; you need to use `getIn()` to access propertiesconsttoken=idx(state,_=>_.user.getIn(['userInfo','token']));
The flowtype shows the error:
81: const countryCode = idx(state, _ => _.country.getIn(['selectCountry', 'countryCode']));
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function call. idx() callbacks may only access properties on the callback parameter!
I need to change code to this to suppress flowtype warnings:
Is there a reason why you want to use Immutable's getIn inside of idx? The example code here could just be replaced with user.getIn(["userInfo", "token"]), which is already safe in the case where those nested keys might not exist.
I suppose you might want to use the two together in a case where some of the nested objects were plain JS objects?
In any event, the machinery that idx uses to make the nested lookup safe only works when accessing nested properties. It doesn't work when accessing inherited methods like getIn. So I don't think your request to make this work is going to happen. But if you can tell me more about the specific situation you're in, I bet we can find a creative solution that solves it.
Doing a null-safe chained access with functional methods is not an unusual thing. For example, given an object err that possibly contains a property graphQLErrors which is an array, one value of which possibly contains a property userMessage, we want to extract the first userMessage. One would think one could do:
let msg = idx(err, _ => _.graphQLErrors.find(e => e.userMessage).userMessage)
In languages that support the null-safe operator, like Kotlin or C# this would translate exactly to:
The following code raises a flowtype error when using idx with immutable.js:
The flowtype shows the error:
I need to change code to this to suppress flowtype warnings:
It makes no sense to write such code.
The text was updated successfully, but these errors were encountered: