我正在尝试为与 Vite 捆绑的 React 应用程序设置路径别名tsconfig.json。这是我的相关部分tsconfig.json:
{
"compilerOptions": {
"baseUrl": ".",
...
"paths": {
"*": ["src/*", "node_modules/*"],
"components/*": ["src/components/*"],
"containers/*": ["src/containers/*"],
"pages/*": ["src/constants/*"],
"store/*": ["src/store/*"],
"types/*": ["src/types/*"],
"NestedFolder/*": [
"src/components/NestedFolder/*"
],
}
},
"include": ["src/**/*", "*"]
}
Run Code Online (Sandbox Code Playgroud)
唯一的问题是NestedFolder. 当我以这种方式导入时,一切正常:
import { ComponentName } from "components/NestedFolder/types";
Run Code Online (Sandbox Code Playgroud)
但是,嵌套别名失败:
import { ComponentName } from "NestedFolder/types";
// error
EslintPluginImportResolveError: typescript with invalid interface loaded as resolver
Occurred while linting .../src/components/NestedFolder/canvas/index.ts:1
Rule: "import/namespace"
// error on hover in VS Code …Run Code Online (Sandbox Code Playgroud) 我尝试使用导入的对象为 .eslintrc.js 文件内的全局变量设置一些限制,但导入不起作用。我如何进行动态 eslint 配置?
import {loadedGlobals} from '@/util/globals'
module.exports = {
'globals': Object.keys(loadedGlobals).reduce((acum, key) => {
acum[key] = false
return acum
}, acum),
// ...
}
Run Code Online (Sandbox Code Playgroud)