0

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:

  1. environment. and typescript don't manage to complete it ( inteliisense)
  2. 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;
}
Tuz
  • 1,810
  • 5
  • 29
  • 58

1 Answers1

0

How to manually add a path to be resolved in eslintrc

here is the solution

1 - open eslintrc.

2 add settings object as follows:

"settings": {
    "import/resolver": {
      "node": {
        "paths": ["src"]
      }
    }
},
Tuz
  • 1,810
  • 5
  • 29
  • 58