typebox-codegen icon indicating copy to clipboard operation
typebox-codegen copied to clipboard

Add `Function` code generation for valibot

Open asabatba opened this issue 3 months ago • 0 comments

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.

asabatba avatar Nov 20 '25 07:11 asabatba