quasarframework / app-extension-typescript

Add TypeScript to your existing Quasar 1.0 JS project

Home Page:https://quasar.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ProcessEnv is always string | undefined, but the truth is it can be boolean

FPNL opened this issue · comments

I have this problem:

// src/store/index.ts
export default function(/* { ssrContext } */) {
  console.log(process.env);

  const Store = new Vuex.Store({
    modules: {
      // example
    },

    // enable strict mode (adds overhead!)
    // for dev mode only
    strict: process.env.DEV
  });

  return Store;
}
ERROR in /src/store/index.ts(23,5):
TS2322: Type 'string | undefined' is not assignable to type 'boolean | undefined'.
  Type 'string' is not assignable to type 'boolean | undefined'.

In env.d.ts, we know this can be set
but
In node_modules/@types/node/globals.d.ts

declare namespace NodeJS {
  interface ProcessEnv {
        [key: string]: string | undefined;
    }
}

So, I have two questions:

  1. node env should always be string, then how it came out a boolean??
  2. If we don't alter the global.d.ts file, how can we fix this problem by not using this way...
strict: process.env.DEV === true ? true : false

I couldn't find a way to make a boolean definition , but you can at least shorten

strict: process.env.DEV === true ? true : false

to

strict: !!process.env.DEV

I think you could fix it like this
strict: Boolean(process.env.DEV),

process.env.DEV is a string containing the text "true" or "false, but is not a boolean, but you can parse it to boolean