-
Notifications
You must be signed in to change notification settings - Fork 659
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to make this work with Typescript #184
Comments
My second try is correct. But I had wrong config for Android and iOS at that time. |
Just to follow up, if you want to type the individual values, you can do this:
and save it anywhere in your project as something like |
Please be very careful with the above solution from @JulianKingman. With that solution you could wrongly import your environment variables like this: import { ENV_VAR_EXAMPLE, ENV_VAR_EXAMPLE_2 } from 'react-native-config';
console.log(ENV_VAR_EXAMPLE);
// undefined
console.log(ENV_VAR_EXAMPLE_2);
// undefined And of course that won't work. If you still want to use that solution, be sure to import your variables like this instead: import Config from 'react-native-config';
console.log(Config.ENV_VAR_EXAMPLE);
// "something"
console.log(Config.ENV_VAR_EXAMPLE_2);
// "something 2" If you want a better solution, the content of the file declare module 'react-native-config' {
export interface NativeConfig {
ENV_VAR_EXAMPLE: string;
ENV_VAR_EXAMPLE_2: string;
}
export const Config: NativeConfig;
export default Config;
} Then, typescript will warn you if you try to import your environment variables in an incorrect way: import { ENV_VAR_EXAMPLE, ENV_VAR_EXAMPLE_2 } from 'react-native-config';
// Error: Module '"react-native-config"' has no exported member 'ENV_VAR_EXAMPLE'. Did you mean to use 'import ENV_VAR_EXAMPLE from "react-native-config"' instead?
// Error: Module '"react-native-config"' has no exported member 'ENV_VAR_EXAMPLE_2'. Did you mean to use 'import ENV_VAR_EXAMPLE_2 from "react-native-config"' instead?
console.log(ENV_VAR_EXAMPLE);
// undefined
console.log(ENV_VAR_EXAMPLE_2);
// undefined |
Hello everyone, I have a question regarding this problem because I followed the instructions of @asdolo but it doestn't work...
I call this export like that :
Problem : the console returns "undefined". Does anyone has a solution ? |
Wrap your exports
|
This was based on lugg#184 (comment)
I'm trying to make this work with a Typescript project but no success.
Here is sample code:
It'll have this error message:
My other try:
Object Config is still empty.
Sorry for my naive question and thank you for help.
The text was updated successfully, but these errors were encountered: