Let's say I have the following interface and object:
interface Person {
name: string;
lastName?: string;
}
const obj: { [key: string]: Person } = {
a: { name: 'John' },
b: { name: 'Jane', lastName: 'Doe' },
}
This defines the type of the object such that its keys can be any string. But I would like to still be able to infer the keys of the object (as it is static), which, in this case, I can't.
I can do something like this:
type ObjKeys = 'a' | 'b';
const obj: { [key in ObjKeys]: Person } //...
But it's verbose.
Is there a short way of saying "here is the type for all the values of this object but leave the keys as defined statically?"