ProcessEnv is always string | undefined, but the truth is it can be boolean
FPNL opened this issue · comments
Xillis_Wu commented
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:
- node env should always be string, then how it came out a boolean??
- 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
Gordon Blahut commented
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
Filip Delperdange commented
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