arktypea
arktype6mo ago
8 replies
Felix

How to validate all properties without bailing early?

I am using Arktype to validate forms. I would like to show all problems with a form. I am using unions to show some form elements conditionally.

export const OtherPropertyRow = type.merge(
  {
    address: 'string > 0',
    value: 'number',
    mortgage: 'number',
  },
  type({
    includedHow: "'Party1'",
  })
    .or({
      includedHow: "'Party2'",
    })
    .or({
      includedHow: "'Other'",
      arrangement: 'string',
    }),
  type({
    purpose: "'InvestmentProperty'",
  })
    .or({
      purpose: "'BachOrHolidayHouse'",
    })
    .or({
      purpose: "'Other'",
      otherPurpose: 'string',
    }),
);


that's a real world example of what i am building. the problem is when i don't have
includedHow
set, it will not report errors for
address
etc.
Was this page helpful?