fix(experimental): allow null with optional and default: null - #201
Conversation
commit: |
|
| ? T | null | ||
| : T | ||
| : null extends D | ||
| ? T | null |
There was a problem hiding this comment.
When a caller explicitly passes null to a non-optional schema with default: null, InferArgs accepts the call but validate does not apply the default and throws a validation error. For example, { n: null } type-checks for v.object({ n: v.number({ default: null }) }) but fails at runtime with expected number, received null.
Knowledge Base Used: Validation and schema contracts
Summary
optional: trueacceptsnullas well asundefined(types + validate)default: nullis valid on all schema helpers; absence producesnullwithout type-checking it as the field typeTest plan
pnpm testinpackages/experimentalv.string({ optional: true, default: null })typechecks and validates omit/null→null