fabian-hiller / valibot

The modular and type safe schema library for validating structural data 🤖
https://valibot.dev
MIT License
6k stars 186 forks source link

Typesafe introspection #690

Closed joshuajaco closed 2 months ago

joshuajaco commented 3 months ago

Sorry to reopen the introspection discussion again, but I've been wondering if there should be support for introspecting schemas without listing them all in a union yourself.

In the meantime I've created valibot-introspection, which essentially is just a large union of all schemas .

Here's an example of how it could be used to generate constraint validation attributes from a valibot schema: TS Playground

Let me know if this is something you are interested in supporting, or if it should stay as a separate library.

fabian-hiller commented 3 months ago

Personally, I recommend specifying GenericSchema and/or any specific schema type you support. This gives you more control over your code and allows you to specify what kind of schema your function supports. Note that we have added an isOfKind and isOfType type guard utility for better DX.