I have created my own env module following this repo:
https://github.com/codeBelt/Custom-Environment-Variables-Setup
in the index file, I import the environment module and I got an error from typescript ( not a compilation error, the code is working)
import environment from 'environment';
console.log(environment.api);
2 issues:
- environment. and typescript don't manage to complete it ( inteliisense)
- i got "Unable to resolve path to module 'environment'.eslint(import/no-unresolved)"
I have the following files :
enviornments/Base.ts
export default function baseEnv(baseUrl: string) {
const baseAPi = window.config.API_URL || baseUrl;
return {
api: {
settings: `${baseAPi}?action=get_settings`
},
isProduction: true,
isDevelopment: false,
isTesting: false
};
};
export type Environment = ReturnType<typeof baseEnv>;
enviorments/production.ts
import environment, { Environment } from './base';
/*
* base.ts is the default environment for production.
* You shouldn't have to override anything.
*/
const baseApi = 'http://api';
const env = environment(baseApi);
const productionEnv: Environment = {
...env
};
export default productionEnv;
enviornments.d.ts
declare module 'environment' {
import baseEnv from 'environments/base';
const value: ReturnType<typeof baseEnv>;
export default value;
}