Is there a way to type the enum array so that it must include every value of the EPostFromField enum?
This pertains to a mongodb schema, where the goal is to future-proof the enum field in case more enums are added later. The aim is to have the compiler detect an error if the array does not contain all the enum values.
Additionally, it would be ideal to find a solution that ensures the enum array values are all unique :)
export const enum EPostFromField {
Resident = 'resident',
AdminUser = 'admin-user', // Admin <user name>
BoardUser = 'board-user', // Board <user name>
AdminSociety = 'admin-society', // Admin <community name>
BoardSociety = 'board-society', // Board <community name>
}
showPostAs: {
type: String,
default: EPostFromField.Resident,
enum: [
EPostFromField.Resident,
EPostFromField.AdminUser,
EPostFromField.BoardUser,
EPostFromField.AdminSociety,
EPostFromField.BoardSociety,
] as EPostFromField[], // DEVNOTE: Enhance typing to enforce inclusion of *every* unique key from the enum
},