Skip to content

mapOf(contains(...)) does not work as described in documentation #23

@kayneb

Description

@kayneb

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions