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

Cannot use map() with only-optional keys #40

Closed
mattbishop opened this issue Aug 8, 2017 · 4 comments
Closed

Cannot use map() with only-optional keys #40

mattbishop opened this issue Aug 8, 2017 · 4 comments

Comments

@mattbishop
Copy link
Contributor

I expect I could spec an object that has only optional keys. Here is a failing unit test:

  describe("map()", () => {
    it("should allow optional-only keys map()", () => {
      const mapSpec = S.spec.map("optional keys", {
        [S.symbol.optional]: {
          banana: S.spec.string
        }
      });

      S.assert(mapSpec, {});
    });
  });
@mattbishop
Copy link
Contributor Author

Error: Cannot use Keys spec without keys.

@arichiardi
Copy link
Collaborator

I double-checked in clojure and it actually works fine so this is probably a missing piece/bug.

boot.user> (s/def ::optional-map (s/keys :opt-un [::a-key]))
:boot.user/optional-map
boot.user> (s/conform ::optional-map {})
{}
boot.user> (s/conform ::optional-map {::a-key 1})
#:boot.user{:a-key 1}

@arichiardi
Copy link
Collaborator

arichiardi commented Aug 9, 2017

If I interpret the code correctly spec does the check in order, starting from the required keys and then using the optional ones...

However in our case, there is a call to keys here, only for required keys. In this case it throws because there are none in there.

So I was thinking of avoid calling that if we don't have required keys. Hopefully @prayerslayer can confirm this is a good approach, all the tests pass smoothly, but I don't know what was the though behind that part.

@arichiardi
Copy link
Collaborator

arichiardi commented Aug 9, 2017

Also I was wondering why there is a return specifically tailored for required keys...

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

2 participants