An object with property getter methods
interface Obj { x: number; y: string; z?: number; }
const obj = opt<Obj>({ x: 1, y: 'hello' });
const getters = obj.genPropGetters();
getters.orCrash('x') // 1
getters.orNull('y') // 'hello'
getters.orUndef('z') // undefined
getters.orZero('x') // 1
// with custom error
const gettersWithCustomError = obj.genPropGetters(key => `Custom error: ${key} is missing`);
gettersWithCustomError.orCrash('z') // crashes with 'Custom error: z is missing'
gettersWithCustomError.orCrash('z', 'nope, no z') // crashes with 'nope, no z'
Generates property getters for an Opt instance.