我从变量中读取了一些有关要求的问题。这是我要考虑的别名情况。在下面的代码中,projectOpenScripts
是别名。
export default class Resources {
constructor(pathToResourcesFile: string){
// true
console.log(pathToResourcesFile === 'projectOpenScripts/resources/resources.json5')
// works
let parsedResources = require('projectOpenScripts/resources/resources.json5');
// does not work
let parsedResources = require(pathToResourcesFile);
console.log(parsedResources.c)
}
}
tsconfig.json
{
"compilerOptions": {
// ...
"baseUrl": "./",
"projectOpenScripts": ["development/1_Source/1_open/3_scripts"]
},
"types": [
// Need for require() and require.ensure
"webpack-env"
]
}
}
我不能接受我们不能要求变量-这种限制与编程概念相矛盾。除了正确获取resources.json5
之外,我还需要禁止对TypeScript的警告Critical dependency: the request of a dependency is an expression
。