Optional
errorFactory: string | ((key) => string | Error)interface A {x?: number;}
const aFull: A = {x: 4};
opt(aFull).propOrCrash('x'); // 4
const aEmpty: A = {};
opt(aEmpty).propOrCrash('x'); // crash
// with custom error: "Custom error: x is missing"
opt(aEmpty).propOrCrash('x', 'Custom error: x is missing'); // crash
opt(aEmpty).propOrCrash('x', key => `Custom error: ${key} is missing`); // crash
opt(aEmpty).propOrCrash('x', key => new Error(`Custom error: ${key} is missing`)); // crash
Get a field from a wrapped object. Crash if the field is missing or empty, or opt instance is None. Shortcut of Opt.prop + Opt.orCrash.