I often create an “uninitialized” object of following form:
const uninitialized = () => {
throw new Error("Uninitialized");
};
const obj = {
get foo() {
return uninitialized();
},
get bar() {
return uninitialized();
},
get baz() {
return uninitialized();
}
};
What if we could write like following; this is shorter, more straightforward and slightly memory efficient.
const obj = {
get foo: uninitialized,
get bar: uninitialized,
get baz: uninitialized,
};
This pattern often appears when I want to make TypeScript happy where I have to supply an object that has specific shape but is not initialized yet.