Creating XOR (exclusified) key types (solved, mostly) in typescript and typebox #1097
regis-underdog
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have a need to create a schema where I have exclusive-or keys for a schema. For background, I have followed some interesting alleyways on the internet[1][2][3][4].
For clarity, I'll illustrate the solution as of Typebox 0.34.0 and Typescript 5.6.3 and Node 20:
such that
Now expanding upward into my main objective:
such that the results are nearly what we want (I have to reiterate that point [5] is still a potential issue)
[1] https://juhanajauhiainen.com/posts/how-to-type-an-object-with-exclusive-or-properties-in-typescript
[2] #60
[3] #151
[4] https://stackoverflow.com/a/44425486
[5]
there are some compositions that work well so long as you keep unevaluatedProperties and additionalProperties as undefined.
from [2]Beta Was this translation helpful? Give feedback.
All reactions