[Typescript] Get All of an Object’s Values
Let's say we have an object as const:
const frontendToBackendEnumMap = {
singleModule: "SINGLE_MODULE",
multiModule: "MULTI_MODULE",
sharedModule: "SHARED_MODULE",
} as const;
We want to get all values of the object as
"SINGLE_MODULE" | "MULTI_MODULE" | "SHARED_MODULE"
const frontendToBackendEnumMap = {
singleModule: "SINGLE_MODULE",
multiModule: "MULTI_MODULE",
sharedModule: "SHARED_MODULE",
} as const;
type BackendModuleEnum =
typeof frontendToBackendEnumMap[keyof typeof frontendToBackendEnumMap];
type tests = [
Expect<
Equal<BackendModuleEnum, "SINGLE_MODULE" | "MULTI_MODULE" | "SHARED_MODULE">
>
];