Given the following TypeScript example to construct a new object with default values
interface MyInterface {
foo: boolean;
};
const generateMyInterfaceWithDefaults: () => MyInterface = () => { foo: false };
The syntax seems to be invalid because the function needs to have a nested return statement like so
const generateMyInterfaceWithDefaults = () => { return { foo: false }; }; // returns function that returns a new interface of MyInterface
I’m wondering if my first approach can be fixed because primitve objects seem to work fine
const generateFalsy = () => false; // returns boolean
So do I have to use the return statement for non primitive types or is it possible to have something like ( … pseudo code … )
const generateMyInterfaceWithDefaults = () => MyInterface.of({ foo: false }); // fixes the first approach