-
-
Notifications
You must be signed in to change notification settings - Fork 212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
InferOutput not including fallbacks #960
Comments
Hey 👋 thank you for reaching out! Can you provide a minimal example, e.g. via our playground? |
At least this is what I'd expect |
Added |
I think there is a misunderstanding here. What you are looking for is the default value of |
Though why shouldn't I be able to compose fallback with one of the optionals? Or different question how/when is fallback meant to be used? |
So in simple words... the default value is used as the input of the schema when there is "no input", and the fallback value is used as the output of the schema when the validation fails. Therefore, a default value can change the type signature because we know that there will always be a value, but |
And therefore also ensuring that there will always be a value in the output right? So InferOutput could (and I think should) reflect that fallback overrides the optional type, or at least I still don't understand why it shouldn't and what the benefit is? To me fallback is pretty much the same as all other optionals just "more insisting" on continuing the happy path "no matter what" and you combine it with one of the optionals to optionally reflect in the input type that you don't have to provide a value... |
No, because |
Uuuh hadn't considered undefined as a fallback value 😅 And inferring that doesn't work or would be too much? Like if the fallback value is not undefined have the output type be non optional 🤔 |
As shown in the provided playground, if Only default values can affect the output type, because they can ensure that e.g. |
Hey I'm a little confused while improving our schemas as I realized that
InferOutput
doesn't include fallbacks, if the type can be nullish/optional/nullable etc.As stated in the docs
So I'd expect the
InferOutput<schema>
type to be of that resulting type.As I'm using it mostly to parse API inputs to pass into our DB (using Kysely) it correctly complaints that certain fields don't accept null/undefined values, tho the
parsed.output
shouldn't be empty as I provided fallbacks where it makes sense, the idea being that I don't have to provide certain fields to get a default fallback generated.I realized that I can move most of those types to just be
optional
ornullish
tho shouldn't any of those wrapped in afallback
still provide a defined output type?The text was updated successfully, but these errors were encountered: