I use a numeric enum type to set a page's access code:
export enum AdminAccess {
None = 0,
Dashboard = 1 << 0,
ModifyUserInfo = 1 << 1,
Publish = 1 << 2
}
And I want the route to take a parameter which is type AdminAccess, such that it can only choose between the values above:
export interface AuthRouteProps {
children: JSX.Element;
path: string;
pageIdentity: AdminAccess;
exact?: boolean;
}
However the type check didn't work as I expected, the check passes as long as I input number. But what I want is that you can only input AdminAccess.None
, AdminAccess.Dashboard
and etc.
<AuthRoute
path={"somepath"}
pageIdentity={AdminAccess.ModifyUserInfo} // pass check
children={<ModifyUserInfoPage />}
/>
<AuthRoute
path={"somepath"}
pageIdentity={897654987} // also pass check
children={<ModifyUserInfoPage />}
/>
How can I make that work?