Let's say I have a function like this but with many more possible values for the enum parameter:
enum API{
userDetails = "/api/user/details",
userPosts = "/api/user/posts",
userComments = "/api/user/comments",
postDetails = "/api/post/details",
postComments = "/api/post/comments"
//...
};
function callAPI(endpoint: API/*, some more params*/){
// some code to deal with the specified endpoint...
}
callAPI(API.userComments);
The above code works fine, but I need to group the many values of the enum into an organized hierarchical structure in order to make things a little more organized... For example, it would be much better if the syntax for calling the API can be callAPI(API.user.comments) instead of callAPI(API.userComments).
I tried things like the below attempts but it looks like none were accepted as a valid syntax for typescript.
Attempt 1
enum API{
user = {
details : "/api/user/details",
userPorts : "/api/user/posts",
userComments : "/api/user/comments"
}
post = {
postDetails : "/api/post/details",
postComments : "/api/post/comments"
}
}
Attempt 2
enum user {
details = "/api/user/details",
userPorts = "/api/user/posts",
userComments = "/api/user/comments"
}
enum post {
postDetails = "/api/post/details",
postComments = "/api/post/comments"
}
enum API{
user,
post
}
Attempt 3
enum user {
details = "/api/user/details",
userPorts = "/api/user/posts",
userComments = "/api/user/comments"
}
enum post {
postDetails = "/api/post/details",
postComments = "/api/post/comments"
}
enum API{
user = user,
post = post
}
Attempt 4
enum user {
details = "/api/user/details",
userPorts = "/api/user/posts",
userComments = "/api/user/comments"
}
enum post {
postDetails = "/api/post/details",
postComments = "/api/post/comments"
}
enum API{
user:user
post:post
}