我在打字稿中设置了路径别名,.tsconfig所以我的导入看起来更干净。
在我的代码中,当我尝试像这样导入我的界面时
import { ApiResponse } from '@api';
Run Code Online (Sandbox Code Playgroud)
eslint 抱怨:Unable to resolve path to module '@api'
然而,vscode 中的智能感知似乎很好。它能够提供代码预测和“跳转到声明”,这是我.tsconfig正确设置但 eslint 以某种方式错误配置的线索。
在我的tsconfig.json 中,我设置了路径别名,如下所示:
{
"compilerOptions": {
"moduleResolution": "node",
"baseUrl": "./src",
"paths": {
"@api": ["./types/api"]
},
}
}
Run Code Online (Sandbox Code Playgroud)
我的./src/types/api.ts看起来像这样:
// 3rd party API response object
export interface ApiResponse {
....
}
Run Code Online (Sandbox Code Playgroud)
最后,我的.eslintrc.json看起来像这样:
{
"env": {
"node": true
},
"globals": {
"console": true
},
"plugins": ["@typescript-eslint", "prettier"],
"parser": "@typescript-eslint/parser",
"settings": { …Run Code Online (Sandbox Code Playgroud)