Microsoft/TypeScript

auto import with tsconfig alias paths to node_modules

Open

#51.058 geöffnet am 4. Okt. 2022

Auf GitHub ansehen
 (4 Kommentare) (10 Reaktionen) (0 zugewiesene Personen)TypeScript (6.726 Forks)batch import
Domain: LS: Auto-importExperience EnhancementHelp WantedSuggestion

Repository-Metriken

Stars
 (48.455 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 6T 17h) (9 gemergte PRs in 30 T)

Beschreibung

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.

Contributor Guide