I'm looking to create an object from a typescript interface that will store initial empty values:
// Interface I'm looking to mock
interface IMyInterface {
name: string;
posts: string[];
}
From this interface, I would need to initialize an object with initial values based on the interface keys and type, something like:
const initObjFromInterface = (interface: any) => {
// do something
return initObject;
}
const initializedObj = initObjFromInterface(IMyInterface);
Note that I don't know the keys of the interface passed as an argument the initObjFromInterface function!
The returned value of the initObjFromInterface function should be:
console.log(initializedObj);
/* should output:
{
name: "", // empty string
posts: [] // empty array
}
*/