I am working with a const object that is used to simulate enums. My goal is to extract the keys from this object and store them in an array. I want TypeScript to generate an error if any of these keys are missing from the array.
// Enum definition.
export const Status = {
'ACTIVE': 'Active',
'DELETED': 'Deleted'
} as const;
// Enum keys and values.
export type StatusKeys = keyof typeof Status;
export type StatusValues = typeof Status[StatusKeys];
// I want TypeScript to detect any missing keys like 'DELETED' and trigger an error.
// Ideally, this process should be dynamic without the need for manual maintenance.
export const ArrayStatus: StatusKeys[] = ['ACTIVE'];
The purpose of this setup is to ensure that I receive errors whenever I add or remove entries from the const object, prompting me to update my code accordingly.