0

This is my WebStorm editor screen:

enter image description here

Here, WebStorm marks QUASAR_ELECTRON_RELOAD and APP_URL with the red underline and displays TS2345: Argument of type 'string | undefined' is not assignable to parameter of type 'string'.   Type 'undefined' is not assignable to type 'string' and QUASAR_ELECTRON_PRELOAD is undefined or APP_URL is undefined when hovering on.

I've tried to add env.d.ts file on the same directory as electron-main.ts with the following contents, but the error still shows.

/* eslint-disable */

declare namespace NodeJS {
    interface ProcessEnv {
        QUASAR_ELECTRON_PRELOAD: string;
        APP_URL: string;
    }
}

How can I remove the errors?


UPDATE

Adding the following contents to the electron-main.ts solved the problem.
(BTW, ESLint complains on using namespace with this message: ESLint: ES2015 module syntax is preferred over custom TypeScript modules and namespaces.(@typescript-eslint/no-namespace))

declare global {
    namespace NodeJS {
        interface ProcessEnv {
            QUASAR_ELECTRON_PRELOAD: string;
            APP_URL: string;
        }
    }
}

But, changing env.d.ts file's content as the following did not solve the problem.

/* eslint-disable */

declare global {
    namespace NodeJS {
        interface ProcessEnv {
            QUASAR_ELECTRON_PRELOAD: string;
            APP_URL: string;
        }
    }
}

export {};

Maybe WebStorm does not refer the other module file when checking a file's error?

LazyOne
  • 158,824
  • 45
  • 388
  • 391
zeodtr
  • 10,645
  • 14
  • 43
  • 60
  • Can you check the first answer [here](https://stackoverflow.com/q/45194598/8613630)? try to add `declare global` – Tobias S. May 04 '22 at 09:06
  • @TobiasS. Thank you! Please see my UPDATE on the question. But I had to apply the answer somewhat differently. I don't know why... – zeodtr May 04 '22 at 09:53

0 Answers0