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

conditional if() validation does not allow late type matching #24

Open
adrienjoly opened this issue Apr 18, 2019 · 1 comment
Open

conditional if() validation does not allow late type matching #24

adrienjoly opened this issue Apr 18, 2019 · 1 comment
Labels
enhancement New feature or request
Milestone

Comments

@adrienjoly
Copy link

I was expected the following validation code to work, based on https://github.com/bodinsamuel/altheia/blob/master/Documentation.md#if-test-func-then-func-otherwise-func- and https://github.com/bodinsamuel/altheia/blob/master/test/base.test.js#L133:

  alt.any().if({
    test: test => test.array(),
    then: test =>
      test
        .array()
        .min(1)
        .oneOf(alt.string()),
    otherwise: test => test.boolean(),
  }),

... but the test => test.array() expression ends up throwing a test.array is not a function error.

I'm guessing that any() should return an object that still allows type checking methods like array().

@bodinsamuel
Copy link
Owner

Thanks for the report !

You are right that the chaining imply same type but it's optional, this should work better:

 alt.any().if({
  test: () => alt.array(),
  then: () => alt.array().min(1).oneOf(alt.string()),
  otherwise: () => alt.boolean(),
})

Anyway this if is poorly design. I will create a better oneOf for all types that should cover all use cases.

@bodinsamuel bodinsamuel added the enhancement New feature or request label Apr 19, 2019
@bodinsamuel bodinsamuel added this to the v5 milestone Jul 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants