I have a file, where I am using enum to hold all my routes strings
enum LoggedInRoutes {
OAK_URL = 'OakUrl',
PROFILE = 'Profile',
ROOT = 'Root',
}
enum TestingRoutes {
DATA_MANAGEMENT = 'DataManagement',
}
const Routes: { [key: string]: string } = {
...LoggedInRoutes,
...TestingRoutes,
};
export default Routes;
export type RoutesType = LoggedInRoutes | TestingRoutes;
I then import the Routes and use them like so:
import * as React from 'react';
import {Button} from 'react-native'
import { useNavigation } from '@react-navigation/native';
import Routes from './Routes';
const App = () => {
const { navigate } = useNavigation();
return (
<Button
title={'Go to url'}
onPress={() => navigate(Routes.OAK_URL)}
/>
);
};
export default App;
Typescript however throws an error
Argument of type 'string' is not assignable to parameter of type 'never'
Can anyone help? Don't know what I'm doing wrong