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.
From what I can tell, the documentation is inaccurate. It states that you can use
mapOf(contains({ ... }))in much the same way aslistOf(contains({ ... })). My map is shaped as follows:with propType of:
I get the error:
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
containsfunction rather than usemapOf.