'Typescript import aliases not working in VSCode

I'm currently building a NextJS template and trying to configure import aliases.

tsconfig.json aliases-related part:

"baseUrl": "./src",
"paths": {
  "@api/*": ["api/*"],
  "@components/*": ["components/*"],
  "@constants/*": ["constants/*"],
  "@pages/*": ["pages/*"],
  "@store": ["store"],
  "@store/*": ["store/*"],
  "@styles/*": ["styles/*"],
  "@util/*": ["util/*"]
}

Folder structure:

enter image description here

The problem: VSCode alias importing not working properly.

E.g. in _app.tsx, alias import for Redux store is working properly:

enter image description here

1. Problem: alias import for exported type State from Navigation.slice.ts is not working.

Exported type:

enter image description here

VSCode import in Navigation.selectors.ts:

enter image description here

Also here it can be seen that exported constant RootState from src/store/reducer.ts is working properly. The fact that alias import sometimes works and sometimes doesn't is really confusing.

2. Problem: Import for exported constant navigationReducer from Navigation.slice.ts inside reducer.ts not working at all.

Exported constant navigationReducer:

enter image description here

VSCode import in reducer.ts not working at all:

enter image description here

Any help is greatly appreciated!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source