fix: nullable number not passing the nullable checks
This commit is contained in:
parent
abfaedda2d
commit
1ef7c4932d
@ -19,7 +19,7 @@ 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> {
|
||||||
const res = super.parse(input, options)
|
const res = super.parse(input, options)
|
||||||
if (!res.valid) {
|
if (!res.valid) {
|
||||||
return res
|
return this.child.parse(input, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.isNull(res.object)) {
|
if (this.isNull(res.object)) {
|
||||||
|
@ -63,6 +63,14 @@ test('number', () => {
|
|||||||
expect(c.parse(1).valid).toBe(true)
|
expect(c.parse(1).valid).toBe(true)
|
||||||
expect(c.parse('2').valid).toBe(true)
|
expect(c.parse('2').valid).toBe(true)
|
||||||
expect(c.parse(true).valid).toBe(false)
|
expect(c.parse(true).valid).toBe(false)
|
||||||
|
|
||||||
|
// handle parsing a nullable number
|
||||||
|
// @ts-ignore
|
||||||
|
c = s.number().parseString().nullable()
|
||||||
|
expect(c.parse(1).valid).toBe(true)
|
||||||
|
expect(c.parse('2').valid).toBe(true)
|
||||||
|
expect(c.parse(null).valid).toBe(true)
|
||||||
|
expect(c.parse(true).valid).toBe(false)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('object', () => {
|
test('object', () => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user