Skip to content
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

Conflict with block-scoped @types/node on env.d.ts #8

Closed
chernodub opened this issue Nov 22, 2021 · 4 comments
Closed

Conflict with block-scoped @types/node on env.d.ts #8

chernodub opened this issue Nov 22, 2021 · 4 comments

Comments

@chernodub
Copy link
Contributor

chernodub commented Nov 22, 2021

Hi guys, thanks for your work! I was wondering how do you resolve the issue with overriding node-provided process? Also, the type definition is not checked by the compiler (since the file is not incuded into the files section of tsconfig.app.json for multiproject structure), is it intended only to be used by the IDE's autocomplete?

Environment:
Angular v13.0.0
@ngx-env/builder 2.0.0
image

Thanks!

@chernodub
Copy link
Contributor Author

Maybe it'll be useful for some people. I was able to resolve the issue by using TS' merge declaration. Although be aware as it won't fail in case there is no such property in your env file.

// <project_root>/env.d.ts

declare namespace NodeJS {

  /** Merge declaration with `process` in order to override the global-scoped env. */
  export interface ProcessEnv {

    /**
     * Built-in environment variable.
     * @see Docs https://github.com/chihab/ngx-env#ng_app_env.
     */
    readonly NG_APP_ENV: string;

    // Add your environment variables below 
    /** Test data. */
    readonly NG_APP_TITLE: string;
  }
}

chernodub added a commit to chernodub/ngx-env that referenced this issue Nov 22, 2021
@chihab
Copy link
Owner

chihab commented Nov 22, 2021

Shouldn't the definition file below do it?

declare var process: {
  env: {
    NG_APP_ENV: string;
    NG_APP_TITLE: string;
  };
};

Is the re-declaration error message only on VSCode or do you also get it on the command line (ng serve)?

@chernodub
Copy link
Contributor Author

The re-declaration is only on my IDE since the declaration file is not included in any of the applications in multiworkspace (by default). Anyway, your solution works great, thanks @chihab!

@stephane-tessier
Copy link

Hi

I have the same problem but I didn't understand the fix.

I have src/env.d.ts:

declare let process: {
  env: {
    NG_APP_ENV: string;
    // Replace the line below with your environment variable for better type checking
    NG_APP_apiHost: string;
    NG_APP_apiURL: string;
  };
};

and when I run my linter:

tsc --noEmit && eslint . --ext js,ts --quiet --fix

"Cannot redeclare block-scoped variable 'process'."

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants