Skip to content
This repository has been archived by the owner on Nov 24, 2024. It is now read-only.

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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants