Detect if a schema has a default value by validating undefined.
Uses the Standard Schema ~standard.validate API to detect defaults.
If the schema accepts undefined and returns a value, that value is the default.
This approach is library-agnostic and works with any Standard Schema compliant
library (Zod, Valibot, ArkType, etc.) without needing to introspect internals.
Parameters
schema: unknown
The schema to check for a default value.
Returns undefined| (()=>unknown)
A factory function returning the default, or undefined if no default exists.
Detect if a schema has a default value by validating
undefined.Uses the Standard Schema
~standard.validateAPI to detect defaults. If the schema acceptsundefinedand returns a value, that value is the default.This approach is library-agnostic and works with any Standard Schema compliant library (Zod, Valibot, ArkType, etc.) without needing to introspect internals.