feat: add falthyAsNull
to nullable
This commit is contained in:
parent
2f48637e28
commit
7e176f1fb7
@ -1,9 +1,17 @@
|
||||
import { parceable } from 'Schema'
|
||||
import SchemaItem from '../SchemaItem'
|
||||
import { SchemaInfer, ValidationResult } from '../types'
|
||||
|
||||
export default class SchemaNullable<Type extends SchemaItem> extends SchemaItem<SchemaInfer<Type> | undefined> {
|
||||
public constructor(public readonly child: Type) { super([child]) }
|
||||
|
||||
@parceable()
|
||||
public falthyAsNull() {
|
||||
this.addPreProcess((it) => !it ? undefined : it)
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
public unwrap(): Type {
|
||||
return this.child
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user