mapOf(contains(...)) does not work as described in documentation
kayneb opened this issue · comments
From what I can tell, the documentation is inaccurate. It states that you can use mapOf(contains({ ... }))
in much the same way as listOf(contains({ ... }))
. My map is shaped as follows:
Map({
selected: true,
tabName: 'Blah'
})
with propType of:
item: ImmutablePropTypes.mapOf(
ImmutablePropTypes.contains({
selected: React.PropTypes.bool.isRequired,
tabName: React.PropTypes.string.isRequired
})
).isRequired
I get the error:
Failed propType: Invalid prop `0` of type `string` supplied to `SideNavItem`, expected an Immutable.js Iterable
Looking into what's actually executed, it seems like mapOf() converts the object being validated on to an array, rather than to an object. That is because listOf and mapOf reuse the same code, createIterableTypeChecker
.
It seems like the only way to validate a map is to just directly use the contains
function rather than use mapOf
.
Same as #15? Seems like this functionality is something that a lot of people are looking for.
Ah yep my bad
Yep sure does. Thanks @hartzis