Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

validate shape of Map #15

Closed
indeyets opened this issue Nov 9, 2015 · 7 comments
Closed

validate shape of Map #15

indeyets opened this issue Nov 9, 2015 · 7 comments

Comments

@indeyets
Copy link

indeyets commented Nov 9, 2015

Currently, I can either validate that something is a Map or that something contains specific keys/values.

Can I do both at the same time?
I want to validate that something is an immutable Map with specific keys, which have values of specific types.

At first, I had an idea that mapOf would do the thing, but it validates each of map's values against pattern.

@sentience
Copy link

I have this question too.

@HurricaneJames
Copy link
Owner

If it contains specific keys/values, then isn't it a Map or a Map descendant by default? What would be the scenario where you want to verify specific key/values and specifically care about the implementing class?

And sorry for the delay. I recently changed jobs and moved from the east coast to the west... ie. I have been a bad project maintainer.

@MatthewHerbst
Copy link

You can apply the same logic as used in React PropTypes. Look at this SO question for the how, and refer to #17 for making sure you realize you will get a normal JS type.

@HurricaneJames
Copy link
Owner

I think the SO question actually references a slightly different problem, ie verifying that something is a Map<string, Object> (map from string to Object). That is an interesting problem, and not one that is handled by this library currently. I would be more than happy to accept a PR for such a feature though.

@MatthewHerbst
Copy link

@HurricaneJames to generalize a little more, the SO questions asks about how you can verify type and/or format of the keys of a map, not just the values of those keys.

@hartzis
Copy link
Contributor

hartzis commented Feb 12, 2016

please check out PR #24 to see if it fits the requested functionality

@HurricaneJames
Copy link
Owner

This should be addressed by #24, which has been merged/published as v1.7.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants