Skip to content

Is array contains supported? #438

Answered by sinclairzx81
joshuaavalon asked this question in Q&A
Discussion options

You must be logged in to vote

@joshuaavalon Hi,

TypeBox doesn't expose the contains keyword (currently) as it's not supported in the type checkers, however you are still free to specify the contains keyword (as well as minContains and maxContains) on the ArrayOptions.

The following is fine if using Ajv.

// Expect an array of numbers, one or more should be equal to 1.
const T = Type.Array(Type.Number(), {
  contains: Type.Literal(1),
})

Maybe I should implement type checker support for this keyword? (There's some considering going into implement additional keywords that mean little to TS, but can be useful on the validation side, other examples include if/then/else, dependentRequired etc)

Hope this helps
S

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by joshuaavalon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants