TypeScript: Inconsistent and broken Auto import in VSCode
Hereby I confirm I did search and read dozen of auto import issues, but they were not related or outdated.
TypeScript Version: 2.7.2
Search Terms: auto import relative absolute tsconfig baseUrl paths
Code
This is my project structure and code. Look for Account.

//tsconfig.json
"baseUrl": "./",
"paths": {
"~/*": ["src/*"]
}
Expected behavior:
- With
pathsturned OFF (code commented) Expected is that I am offered with correct relative paths- for
index.tsfileAuto import from './Account/Account' ; class Account- import is already correctAuto import from './routes' ; CONST ACCOUNT- correct - for
SignIn.tsxfileAuto import from '../Account/Account' ; class Account- this import is missingAuto import from '../routes' ; CONST ACCOUNT- correct
- for
- With
pathsturned ON (code uncommented) Expected is that I am offered with correct relative AND absolute paths- for
index.tsfileAuto import from './Account/Account' ; class Account- missingAuto import from '~/pages/Account/Account' ; class Account- correctAuto import from './routes' ; CONST ACCOUNT- missingAuto import from '~pages/routes' ; CONST ACCOUNT- correct - for
SignIn.tsxfileAuto import from '../Account/Account' ; class Account- missingAuto import from '~/pages/Account/Account' ; class Account- missingAuto import from '../routes' ; CONST ACCOUNT- missingAuto import from '~pages/routes' ; CONST ACCOUNT- correct
- for
Actual behavior: note that there are also some completely wrong import suggestions
pathsOFF- error1: path
'.'is invalid - there is no localy available export
- error2: no class imports are available at all

- error1: path
pathsON- error3: path
'~/pages'is invalid - there is no available export
- error4: no class imports are available at all

- error3: path
note: Auto import in a root file App.tsx finds the class exports.
note2: There is still the wrong import from src/pages folder.
paths OFF
paths ON

So far I have counted 6 missing import suggestions and 4 wrong import suggestions. I am verry confused by the actual behaviour. It looks like I can import from any parent folder of importing module, but not from a sibling folder. Restarting computer didn’t help.
Am I missing something? What’s wrong with my configuration?
Related Issues: Autoimport always imports relative to baseUrl #19920
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 17
That screenshot shows that the completions are giving you one way of getting the identifier. We intentionally avoid adding many different completions for the same identifier.