fix: nullable not correctly parsing value

This commit is contained in:
Florian Bouillon 2025-04-02 14:01:02 +02:00
parent 614b7c0185
commit 527b9a8394
Signed by: Florian Bouillon
GPG Key ID: 7676FF78F3BC40EC

View File

@ -17,7 +17,12 @@ export default class SchemaNullable<Type extends SchemaItem> extends SchemaItem<
}
public override parse(input: unknown, options?: { fast?: boolean }): ValidationResult<SchemaInfer<Type> | undefined> {
if (this.isNull(input)) {
const res = super.parse(input, options)
if (!res.valid) {
return res
}
if (this.isNull(res.object)) {
return {
valid: true,
object: undefined
@ -28,7 +33,7 @@ export default class SchemaNullable<Type extends SchemaItem> extends SchemaItem<
}
public override isOfType(input: unknown): input is SchemaInfer<Type> | undefined {
return Array.isArray(input)
return this.isNull(input) || this.child.isOfType(input)
}
private isNull(value: unknown): value is undefined | null {