Can I get an objects actual keys when I'm using an interface to describe the object?
Example below
interface IPerson {
name: string;
}
interface IAddress {
[key: string]: IPerson;
}
const personInAddressObj: IAddress= {
someAddress1: {
name: 'John',
},
someAddress2: {
name: 'Jacob',
}
} as const
type Keys = keyof typeof personInAddressObj;
Id want the type Keys to have the values "someAddress1 | someAddress2". If I take the interface out of "personInAddressObj", I can get the keys. However, when the interface is used, I can't get the actual keys out of the object.
Object.keys(personInAddressObj), which gets you the keys as array of strings. Have a look here: developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…as const) are compile-time information.personInAddressObj, I can get the keys." - so, why not do that? There's no point in usingas constif you did assign to a variable declared asIAddress.