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. image

//tsconfig.json
    "baseUrl": "./",
    "paths": {
      "~/*": ["src/*"]
    }

Expected behavior:

  1. With paths turned OFF (code commented) Expected is that I am offered with correct relative paths
    1. for index.ts file Auto import from './Account/Account' ; class Account - import is already correct Auto import from './routes' ; CONST ACCOUNT - correct
    2. for SignIn.tsx file Auto import from '../Account/Account' ; class Account - this import is missing Auto import from '../routes' ; CONST ACCOUNT - correct
  2. With paths turned ON (code uncommented) Expected is that I am offered with correct relative AND absolute paths
    1. for index.ts file Auto import from './Account/Account' ; class Account - missing Auto import from '~/pages/Account/Account' ; class Account - correct Auto import from './routes' ; CONST ACCOUNT - missing Auto import from '~pages/routes' ; CONST ACCOUNT - correct
    2. for SignIn.tsx file Auto import from '../Account/Account' ; class Account - missing Auto import from '~/pages/Account/Account' ; class Account - missing Auto import from '../routes' ; CONST ACCOUNT - missing Auto import from '~pages/routes' ; CONST ACCOUNT - correct

Actual behavior: note that there are also some completely wrong import suggestions

  1. paths OFF
    1. error1: path '.' is invalid - there is no localy available export import1
    2. error2: no class imports are available at all image
  2. paths ON
    1. error3: path '~/pages' is invalid - there is no available export import2
    2. error4: no class imports are available at all image

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 import4 paths ON import3

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

Most upvoted comments

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.