object-shape-tester - v6.3.3
    Preparing search index...

    Function nullableShape

    • Creates a shape that is optional, possibly null, and possibly undefined.

      Type Parameters

      • T

      Parameters

      • shape: T

      Returns Shape<TOptional<TUnion<ShapeInitSchema<undefined | null | T>[]>>>

      import {nullableShape, checkValidShape, defineShape} from 'object-shape-tester';

      const myShape = defineShape({
      a: '',
      b: nullableShape(-1),
      });

      checkValidShape({a: 'hi', b: 0}, myShape); // `true`
      checkValidShape({a: 'hi', b: undefined}, myShape); // `true`
      checkValidShape({a: 'hi', b: null}, myShape); // `true`
      checkValidShape({a: 'hi'}, myShape); // `true`
      checkValidShape({b: 0}, myShape); // `false`