I've set up path aliasing in typescript's .tsconfig
so my imports look cleaner.
In my code when I try and import my interface like this
import { ApiResponse } from '@api';
eslint complains: Unable to resolve path to module '@api'
However, intelisense in vscode seems fine. Its able to give code prediction and "Jump to declaration" which is a clue that my .tsconfig
is set up correctly but eslint is somehow misconfigured.
Relevant files
In my tsconfig.json, I've set up path aliasing like so:
{
"compilerOptions": {
"moduleResolution": "node",
"baseUrl": "./src",
"paths": {
"@api": ["./types/api"]
},
}
}
My ./src/types/api.ts looks like this:
// 3rd party API response object
export interface ApiResponse {
....
}
Finally, my .eslintrc.json looks like this:
{
"env": {
"node": true
},
"globals": {
"console": true
},
"plugins": ["@typescript-eslint", "prettier"],
"parser": "@typescript-eslint/parser",
"settings": {
"import/extensions": [".js", ".ts"],
"import/parsers": {
"@typescript-eslint/parser": [".ts"]
},
"import/resolver": {
"node": {
"extensions": [".js", ".ts"]
}
}
}
}
Any idea what I may be doing wrong?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…