I've been facing challenges trying to pinpoint the root cause of the issue with this code. It would be greatly appreciated if someone could shed light on what is triggering the problem and possibly suggest a solution.
Within my application, I am attempting to utilize an enum to outline the routes employed by a router. While it was successful in certain scenarios, for some reason, in the current context where I am implementing the enum, it is not functioning as expected.
In instances where it works correctly, the code may resemble the following:
history.push(routes.testPage)
In contrast, when it fails to work, it resembles something like this:
const enum routes {
index = '/',
testPage = '/test',
}
const adminRoutes = [
routes.testPage,
];
const routeIsAdmin = (route: string) => adminRoutes.indexOf(route) > -1;
The specific error message I receive in this scenario reads:
Argument of type 'string' is not assignable to parameter of type 'routes'
I've created an example of this code on the TypeScript playground.
Would appreciate any insights or explanations regarding this matter?
Edit
To provide further clarity, adding any string to the array adminRoutes
resolves the issue without any complications. However, this workaround is not ideal, but it might offer some insight into the underlying problem.