我有以下env.js
JS文件:
const env = {
ENV: process.env.NODE_ENV,
DEBUG:
(process.env.REACT_APP_DEBUG == 1 ||
process.env.REACT_APP_DEBUG === "true"),
PUBLIC_URL: process.env.PUBLIC_URL
};
export default env;
当我将其导入另一个文件并尝试引用env
的对象属性之一时:
import env from "./env";
const DEBUG = env.<I start typing and I do not see any autocomplete for ENV, DEBUG or PUBLIC_URL>
VS Code不会自动完成env
对象的属性。
为什么不执行该操作?如何在这种情况下对其进行修复以使自动完成功能起作用?
这是我的tsconfig.json
{
"compilerOptions": {
// No module system, concatenated file
"module": "none",
// Set React as the JSX factory
"jsx": "react",
// Resolve modules using Node-resolution algorithm
"moduleResolution": "node",
// Target ES6 for more modern browsers
"target": "es6",
// Include typings from built-in lib declarations
"lib": ["es2015", "dom", "dom.iterable"],
// Include module source maps for debugging
"sourceMap": true,
// Output to single concatenated file
"outFile": "dist/bundle.js",
"allowJs": true,
"allowSyntheticDefaultImports": true
},
"include": ["src"],
"exclude": ["node_modules"]
}
我还注意到,如果我将env.js
更改为:
export default {
ENV: process.env.NODE_ENV,
DEBUG:
(process.env.REACT_APP_DEBUG == 1 ||
process.env.REACT_APP_DEBUG === "true"),
PUBLIC_URL: process.env.PUBLIC_URL
}
然后,自动完成功能将起作用:
import env from "./env";
const DEBUG = env.<I start typing and I see the autocomplete for ENV, DEBUG or PUBLIC_URL>
为什么在第二种情况下却不能在第一种情况下起作用?