Skip to content
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

Feature Request: Revert of optional()and nullable #254

Open
zhaoyao91 opened this issue May 8, 2021 · 3 comments
Open

Feature Request: Revert of optional()and nullable #254

zhaoyao91 opened this issue May 8, 2021 · 3 comments

Comments

@zhaoyao91
Copy link

Some base schema defined some fields as optional, but when used in a concrete situation, we may need to assume it as required. It would be good to have revert operators such as required() and notNull

@yuhr
Copy link
Collaborator

yuhr commented May 8, 2021

This seems to be a feature request rather than a question. If you provide some example code then I can provide a workaround for you. Maybe .extend() should work for your case:

Record({ x: String.optional() }).extend({ x: String })

Well, I think required is a reasonable feature to implement as is. As for notNull (I prefer nonNull BTW), we should implement a feature like .exclude() e.g. Union(A, B).exclude(B) === Union(A) at first, since nullable types are just Unions including Null as their alternatives, and then implement .nonNull() as an alias for .exclude(Null).

@yuhr yuhr changed the title Question: Revert of optional()and nullable Feature Request: Revert of optional()and nullable May 8, 2021
@zhaoyao91
Copy link
Author

zhaoyao91 commented May 9, 2021

Cool~ look forword to
The problem of current extend workaround is, we have to have knowledge of the original field to make it again, which is duplicated and weak.

@yuhr
Copy link
Collaborator

yuhr commented May 10, 2021

Okay, then you can use Optional(A).underlying to unwrap it for now, but it should be deprecated and replaced soon by .required() which has more understandable name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants