I have this code:
type Foo = {
fiz: 'baz',
bar: 'biz'
}
const foo: Partial<Foo> = {}
Essentially, the type will change a lot, and I want to do smth like this:
Object.keys(Foo).map(key=>{
foo[key] = null;
})
But that's obviously impossible. Is there a way to make it work dynamically? Or am I stuck with typing each key dynamically?
Im not entirely sure what your goal is. Are you trying to ensure your objects will always start with all keys, even if they have no values?. I dont think this would be possible based on the type due to the type not existing at runtime. Instead you could create an object of that type with all keys and use the spread operator {...foo} to create other objects with those keys (Example).