I have some global variables that I inject into my React application with Webpack.
const globals = {
BACKEND_URL: 'https://example.com',
ENVIRONMENT: 'production',
...
};
export default globals;
I have injected them, but I would also like typescript to be able to pick them up automatically. Usually, you would map over types like this :
{ [P in globalKeys]: globalType[P] };
But I am not sure how to put that into the global context. Mapped types are only available on types, but Window is an interface.
They should be available in the global context (via implicit window
), e.g.
const isProduction = ENVIRONMENT === "production"; // ENVIRONMENT is defined