Rhys - const formSchema = z .object({ veh...
- Trying to make it so replacing is optional and if replacing is set to true then replacingReg needs to be required, otherwise its optional. Anyone got some advice 🙂
Solution:Jump to solution
If the flaky types from the
refine
approach is not a problem for you, it is probably the easier solution to maintain.
By flaky types I am referring to the fact that you cannot do exhaustive checks with TS like you can with discriminated unions:
```ts
// Refine approach
const data = formSchema.parse(...);...3 Replies
You can either do something like this:
Or you can utilize discriminated unions and use
replacing
as your discriminator:
The discriminated unions approach will make you repeat the properties, however nothing would stop you from extracing the common properties to another variable:
Solution
If the flaky types from the
refine
approach is not a problem for you, it is probably the easier solution to maintain.
By flaky types I am referring to the fact that you cannot do exhaustive checks with TS like you can with discriminated unions:
Wow what an indepth response, thank you so much for the assistance @Sikari Will implement these now 🙏
Youre a genius! Worked first time, I tried the dsicriminated approach, felt the most readable and easily adjustable, thanks very much!