-
-
Notifications
You must be signed in to change notification settings - Fork 22
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
Question: How to allow optional fields to be omitted? #35
Comments
Hey @CodingDive! 👋🏻 That's not how you should extract the type from the validator; you should use import vine from '@vinejs/vine'
import type { Infer } from '@vinejs/vine/types'
const schema = vine.object({
username: vine.string(),
email: vine.string().email(),
password: vine
.string()
.minLength(8)
.maxLength(32)
.confirmed()
})
type UserRegistration = Infer<typeof schema> 📚 https://vinejs.dev/docs/getting_started#inferring-types-from-schema |
This simplifies the code quite a bit 😅 Thank you! I'd still need the |
how can we make all the field optional in vine object |
I am also struggling with this, I've used the provided type UndefinedKeys<T> = {
[K in keyof T]: undefined extends T[K] ? K : never;
}[keyof T];
type OmitUndefined<T> = Omit<T, UndefinedKeys<T>> & Partial<Pick<T, UndefinedKeys<T>>>; |
This has been fixed by #79. However, it is a breaking change and I will release it as a major release with few another planned improvements. |
Fixed in Vine 3.0 https://github.com/vinejs/vine/releases/tag/v3.0.0 |
Package version
Latest (1.7.1)
Describe the bug
Thank you for this fantastic library and all the work in Adonis v6! ❤️
I tried to follow https://vinejs.dev/docs/schema_101#nullable-and-optional-modifiers
however, when I extract the type out of the validator:
type UpdateUser: Awaited<ReturnType<typeof updateUserValidator.validate>>
I can see that the resulting type ispassword: string | null | undefined;
. Is there a way to make itpassword?: string | null | undefined
?I could write a TypeScript helper to accomplish this in user land but it's not that pretty and I was wondering if there is an easier way.
Small aside: In the repo, when clicking on "Get Help => Open", a new tab opens but it doesn't fill out the issue template with Question.
The text was updated successfully, but these errors were encountered: