Dynamically .merge
or .extend
#1172
Unanswered
fehnomenal
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
First of all thanks for this great library. I use it everywhere I can 👍
Lately I work with Rest APIs where the response shape depends on the request.
It is something like this
The response will contain generic article information only if
includeGenericArticles
was given astrue
:At runtime I can express this easily by building the response schema dynamically:
This works and now I want to get type-safety also at compile time, i.e.:
It tried it with generics, conditional types and
z.extendShape
but it won't work:If I remove the ternary and use always the extension shape, it type checks.
Has anybody an idea how I can solve this problem?
Beta Was this translation helpful? Give feedback.
All reactions