Optional required pairs?
I have a type that has all optional properties. However I want to want to make 2 options a pair - if one exists, the other is required.
An example:
Is this doable? I'm using Arktype for validating incoming JSON in a server, so the use case for it is changing passwords, if you want to change your password you need to provide the current password as well, and maybe the new password a second time to confirm it
2 Replies
One way would be to use
.narrow()
, which has the added benefit of being able to specify custom errors:@Tony You could use something like this: