react-native-keys icon indicating copy to clipboard operation
react-native-keys copied to clipboard

Question: TypeScript Declarations for react-native-keys

Open imdangle opened this issue 1 year ago β€’ 1 comments

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 avatar Aug 19 '24 07:08 imdangle

πŸ‘‹ @imdangle Thanks for opening your issue here! If you find this package useful hit the star🌟!

github-actions[bot] avatar Aug 19 '24 07:08 github-actions[bot]

@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
}

iurybrasileiro avatar Apr 13 '25 00:04 iurybrasileiro