typebox-codegen
typebox-codegen copied to clipboard
Add `Function` code generation for valibot
Hi!
This commit adds code generation for functions for valibot.
Currently, functions were treated as an unsupported type. In reality, valibot has the following function-centric methods:
- https://valibot.dev/api/function/
- https://valibot.dev/api/args/
- https://valibot.dev/api/returns/
Which allow the user to specify expected argument and return types.
export type F = v.InferOutput<typeof F>
export const F = v.pipe(
v.function(),
v.args(v.tuple([v.number()])),
v.returns(v.void())
)
Now, this feature, when used with valibot's parse or safeParse utilities, will modify the input function and add runtime type checks. This might not always be desirable, but the user can use the assert or is checks if the original data should be unchanged.