UNPKG

ts-cast

Version:
6 lines (5 loc) 290 B
import { withName } from '../helpers/names'; import { throwTypeError } from './throw-type-error'; export const nullable = (caster) => withName((value, context, reportError = throwTypeError) => (value !== null ? caster(value, context, reportError) : null), `${caster.name} | null`);