freddi301/flow-validator

View on GitHub
src/async/asyncOptional.js

Summary

Maintainability
A
2 hrs
Test Coverage
// @flow

import { AsyncType, AsyncOptionalType } from "./AsyncType";

export function asyncOptional<T>(t: AsyncType<T>): AsyncOptionalType<T> {
  return new AsyncOptionalType(t, async v => {
    if (v === null || v === void 0) return v;
    return t.parse(v);
  });
}