-
-
Notifications
You must be signed in to change notification settings - Fork 216
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
v.optional output type is broken #935
Comments
As a sidenote, the behavior of Either way, the TypeScript types are incorrect because it expects |
Thank you for reaching out! You are right! I am very sorry. I will fix this and add tests to make sure this cannot happen again.
|
Fixed 😎 |
What information do you miss in the docs? I am happy to improve it. Here is our guide and API reference: |
@fabian-hiller Thank you! This is what I found confusing about the docs:
I think I now understand that this is saying, "if you do not provide a default value, the input type of the schema will expand to also allow But the way I read it was, "if you do provide a default value, the output type of the schema will expand to include the default value's type, since the default value will be returned directly as output if the input is |
Thank you. I will have another look at the docs at the end of the year to see if we can improve the explanation. |
I believe this bug was introduced in v1.0.0-beta.3. When wrapping a transform schema in
v.optional
with a default value, the inferred output type is now a union including the type of the default value. However, at runtime the default value is still parsed through the transform schema.Tricky to explain, so here is a playground example.
The schema will always return a
number
, but now TypeScript says it will returnnumber | "10"
The text was updated successfully, but these errors were encountered: