Microsoft/TypeScript

auto import with tsconfig alias paths to node_modules

Open

#51.058 aperta il 4 ott 2022

Vedi su GitHub
 (4 commenti) (10 reazioni) (0 assegnatari)TypeScript (6726 fork)batch import
Domain: LS: Auto-importExperience EnhancementHelp WantedSuggestion

Metriche repository

Star
 (48.455 star)
Metriche merge PR
 (Merge medio 6g 17h) (9 PR mergiate in 30 g)

Descrizione

Does this issue occur when all extensions are disabled?: Yes

  • VS Code Version: 1.71.2
  • OS Version: Windows 11

Steps to Reproduce:

  1. Configure a tsconfig.json which has alias paths to node_modules

    {
      "compilerOptions": {
        "allowJs": true,
        "jsx": "react",
        "baseUrl": ".",
        "checkJs": true,
        "noEmit": true,
        "esModuleInterop": true,
        "resolveJsonModule": true,
        "paths": {
          "theme/*": [
            "./src/web/theme/*",
            "./node_modules/my-library/my-module-a/web/theme/*",
            "./node_modules/my-library/my-module-b/web/theme/*",
            "./node_modules/my-library/my-module-c/web/theme/*",
          ],
          "web/*": [
            "./src/web/*",
            "./node_modules/my-library/my-module-a/web/*",
            "./node_modules/my-library/my-module-b/web/*",
            "./node_modules/my-library/my-module-c/web/*",
          ],
          "server/*": ["./node_modules/my-library/src/server/*"],
          "config/*": [
            "./src/config/*",
            "./node_modules/my-library/my-module-a/config/*",
            "./node_modules/my-library/my-module-b/config/*",
            "./node_modules/my-library/my-module-c/config/*",
          ],
        }
      }
    }
    
  2. Try to import an existing file under the alias in node_modules

The autocomplete would prefer to use the my-library as a package instead of the shorter alias path, for example it would suggest:

import Image from "my-library/my-module-a/web/theme/Image"
import Image from "my-library/my-module-b/web/theme/Image"
import Image from "my-library/my-module-c/web/theme/Image"

But it will not suggest:

import Image from "theme/Image"

although that alias works perfectly fine when adding it manually.

Guida contributor