My enum type is structured as follows:
export enum API_TYPE {
INDEX = "index_api",
CREATE = "create_api",
SHOW = "show_api",
UPDATE = "update_api",
DELETE = "destroy_api"
};
Presently, I have a function that requires a numeric ID and an api_type parameter.
export function abc (id: number, api_type:?) =>
The valid values for the api_type parameter in this function correspond to the keys of the API_TYPE
enum.
What would be the most optimal way to define the type of the api_type
parameter in the function abc
?
One option could involve creating a new type named Api_Type
with specific string literals:
and then
export function abc (id: number, api_type:Api_Type) =>
However, with this approach, any additional properties added to the enum API_TYPE {
will also need to be manually included in the Api_Type
.
Is there a method to automatically map enum values to types, or perhaps a better alternative for handling this situation?