-
-
Notifications
You must be signed in to change notification settings - Fork 204
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
Type issue with nested generic type #878
Comments
Can you provide a playground link? I am sure this is fixable. https://valibot.dev/playground/ |
I guess issue is caused by wrong usage of |
I would like to replace In the meantime you have two workarounds. You could add import * as v from 'valibot';
function mySchema<T extends v.GenericSchema>(schema: T) {
return v.pipe(v.optional(schema, undefined), v.check(() => true));
}
const schema = mySchema(v.number()); import * as v from 'valibot';
function mySchema<T extends v.GenericSchema>(schema: T) {
// @ts-expect-error
return v.pipe(
// @ts-expect-error
v.optional(schema),
v.check(() => true),
) as v.SchemaWithPipe<
[
v.OptionalSchema<T, never>,
v.CheckAction<v.InferOutput<T> | undefined, undefined>,
]
>;
}
const schema = mySchema(v.number()); |
I think this is because the definitions of const nullishSchema = z.number().nullish().default(1);
console.log(nullishSchema.parse(undefined)); // 1
console.log(nullishSchema.parse(null)); // null
const nullableSchema = z.number().nullable().default(1);
console.log(nullableSchema.parse(null)); // null Both in Another example, many ORM like sequelize and TypeORM treat Requirement and solution:
In summary (in valibot):
If you still think a default value is necessary for |
Thank you for your recommendation! I like your idea and will think about it! |
I am currently investigating your suggestion and think I will follow it. |
v1.0.0-beta.3 is available |
I don't understand why TypeScript tell me a error, I think this is a common use case
The text was updated successfully, but these errors were encountered: