fix: nullable not correctly parsing value
This commit is contained in:
parent
614b7c0185
commit
527b9a8394
@ -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> {
|
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 {
|
return {
|
||||||
valid: true,
|
valid: true,
|
||||||
object: undefined
|
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 {
|
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 {
|
private isNull(value: unknown): value is undefined | null {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user