react-native-keys
react-native-keys copied to clipboard
Question: TypeScript Declarations for react-native-keys
Hi,
We recently migrated from react-native-config to react-native-keys for improved security when handling environment variables in our React Native project. We loved the TypeScript declarations that react-native-config offered
Is there a similar way to generate or provide TypeScript declarations for variables managed by react-native-keys? This would be incredibly helpful for type safety and code completion in our TypeScript codebase.
Any guidance or best practices you can provide would be greatly appreciated.
Thanks!
π @imdangle Thanks for opening your issue here! If you find this package useful hit the starπ!
@imdangle I guess I'm too late, but, I was looking for the same thing than you, so, I'll left a comment any way because it could help someone else.
I did a quick test and looks it works
declare module 'react-native-keys' {
export type TSecureEnvironmentVariables = undefined
export type TPublicEnvironmentVariables = {
ENVIRONMENT: 'production' | 'development'
API_BASE_URI: string
}
type TEnvs = {
secureFor: (key: keyof TSecureEnvironmentVariables) => string
publicKeys: () => TPublicEnvironmentVariables
} & TPublicEnvironmentVariables
export const EnvironmentVariables: TEnvs
export default EnvironmentVariables
}