-
-
Notifications
You must be signed in to change notification settings - Fork 72
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
Add an option to allow undefined
for optional properties
#1191
Comments
Are there any updates?🧐 |
I would accept external contributions on this. Otherwise it would likely be sometime after stable 2.0. |
Out of merely interest is there actually any way to get exactly this proposed API to work? configure({ optionalAllowsUndefined: true }); Traditionally I've had to have something like this: configure({ optionalAllowsUndefined: true });
declare module "arktype/configuration" {
interface Config {
optionalAllowsUndefined: true
}
} |
ArkType uses a global called This is something I'm working on documenting more now. However, this wouldn't be a type-level config. You would just change this setting to match the |
I would like to have this feature in Arktype. I am dealing with data that often has null values as the python schemas have no means of precluding it (though they do make it possible to drop such values during JSON encoding, it's just not guaranteed to be used). My solution up until now is to define fields like It seems the proposal so far has focused on just |
@trsaunders Since this would parallel the That may be addressed separately though along with some other cases like empty strings that potentially should be treated as not present in contexts like forms. |
That could work. For my use-case I don't mind specifically annotating a field to say that null implies not present, such that the fields get ignored during validation, and the type appears as optional. Is that the sort of thing you had in mind? |
@trsaunders I'm not sure exactly what the API would be yet. It would likely be configurable both globally and for an individual field. Actually if you wouldn't mind creating an issue for that I'd appreciate it! |
Request a feature
Add a global option to allow
undefined
as a value for optional properties.🤷 Motivation
The type above produces the type
{ phoneNumber?: string }
and will not validate{ phoneNumber: undefined }
at runtime.💡 Solution
Another solution could be a new-ish syntax like
string??
.The text was updated successfully, but these errors were encountered: