import {
nullToNullableShape,
unionShape,
assertValidShape,
defineShape,
} from 'object-shape-tester';
const myShape = nullToNullableShape({
a: '',
b: unionShape(null, -1),
c: null,
d: {
e: unionShape(null, ''),
},
});
// passes
assertValidShape({a: 'hi', b: null, d: {}}, myShape);
assertValidShape({a: 'hi', b: undefined, d: {e: undefined}}, myShape);
// fails
assertValidShape({b: null}, myShape);
assertValidShape({a: 'hi'}, myShape);
Creates a shape from an object shape where any property that can be any kind of nullable (optional,
null
, orundefined
) can now be all kinds of nullable. That is, any property that is optional or can benull
orundefined
becomes all three.