You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As a developer creating integrations with valibot (not using valibot directly, but creating library solutions for other developers on top of valibot), I am missing an option to accept abstract valibot schema, either sync or async. Currently, I have to use v.BaseSchema<Input, Output> | v.BaseSchemaAsync<Input, Output> boilerplate.
Example (simplified) code:
import*asvfrom"valibot"/** * Vue composable: validate input and submit if it's valid. * Simplified for brevity. */exportfunctionuseForm<Input,ValidInput=Input>(options: {fields: Inputschema: v.BaseSchema<Input,ValidInput>|v.BaseSchemaAsync<Input,ValidInput>submit: (data: ValidInput)=>void|PromiseLike<void>}){const{ schema, fields }=optionsreturnasyncfunctionsubmit(){constres=awaitv.safeParseAsync(schema,fields)if(res.success){awaitoptions.submit(res.output)}}}
I propose to export a new common type (such as BaseSchemaMaybeAsync), so that in the code above it'd possible to write:
schema: v.BaseSchemaMaybeAsync<Input,ValidInput>
The text was updated successfully, but these errors were encountered:
Thanks for your feedback on this. I'm not sure yet if I want to add such a type to the library. I think the explicit assignment is better in most cases. As a workaround for now you can create this type yourself.
Thank you for the response. Of course I understand that I can create types and other extensions on my own, especially as trivial as this one.
If you don't think the use case is relevant (even though I provided an example) and/or that this is an anti-pattern, I suppose this issue should be just closed as not planned. I'm inclined to publish some kind of valibotx anyway, which will re-export everything from valibot along with the unobtrusive extensions that you don't want (e.g. #171). :)
My spontaneous feedback is that I prefer an explicit assignment. This is also the approach I currently use in the Valibot source code. However, I understand your approach and depending on the context, it may be better.
I'm open to new ideas, and even if I don't directly agree with a change or extension, I leave it open to change my mind if I get feedback from more people. So I will leave the labels as they are for now and maybe change them in a few months.
Feel free to create a package like valibotx that extends the functionality of Valibot. Maybe in the long run I will take some ideas and implement them directly into Valibot.
As a developer creating integrations with valibot (not using valibot directly, but creating library solutions for other developers on top of valibot), I am missing an option to accept abstract valibot schema, either sync or async. Currently, I have to use
v.BaseSchema<Input, Output> | v.BaseSchemaAsync<Input, Output>
boilerplate.Example (simplified) code:
I propose to export a new common type (such as
BaseSchemaMaybeAsync
), so that in the code above it'd possible to write:The text was updated successfully, but these errors were encountered: