arktypea
arktype16mo ago
Stuart B

Post-morph constraints not checked if constraints not met on another property

If I have:
const schema = type({
    name: 'string>3',
    'age?': type('string.numeric.parse').to('number>18')
});

If I then try:
const result=schema({
    name:'me',
    age:'5'
})


I will get an error for name, but not for age.

If I instead try
const result=schema({
    name:'Stuart',
    age:'5'
})

Then I now get an error about age being <18, now that the 'name' check has passed.

Is this by design?
Was this page helpful?