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

MaybeEmpty and Nullable should have options args #985

Open
motopods-lucas opened this issue Dec 31, 2024 · 1 comment
Open

MaybeEmpty and Nullable should have options args #985

motopods-lucas opened this issue Dec 31, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@motopods-lucas
Copy link

motopods-lucas commented Dec 31, 2024

What is the problem this feature would solve?

t.Nullable t.Empty not support default value.

Value.Parse(t.Object({
  foo: t.Nullable(t.String({ default: null }))
})) // throw  Expected required property.
Value.Parse(t.Object({
  foo: t.Union([t.String(), t.Null()], { default: null })
})) // this works

What is the feature you are proposing to solve the problem?

Allow pass the SchemaOptions to the t.Nullable t.Empty, just like Union<Types extends TSchema[]>(types: [...Types], options?: SchemaOptions): Union;

Nullable: <T extends TSchema>(schema: T, options?: SchemaOptions) => t.Union([schema, t.Null()], options),

What alternatives have you considered?

No response

@motopods-lucas motopods-lucas added the enhancement New feature or request label Dec 31, 2024
@motopods-lucas
Copy link
Author

At

t.Nullable = (schema) => ElysiaType.Nullable(schema)
, it seems that t.Nullable does not pass the options into ElysiaType.Nullable. Additionally, why is an arrow function used here instead of directly assigning a function reference? @SaltyAom

@

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant