Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto import with wildcard imports with expanded path #51398

Open
dtdesign opened this issue Nov 3, 2022 · 6 comments
Open

Auto import with wildcard imports with expanded path #51398

dtdesign opened this issue Nov 3, 2022 · 6 comments
Assignees
Labels
Domain: Auto-import Needs Investigation This issue needs a team member to investigate its status.

Comments

@dtdesign
Copy link

dtdesign commented Nov 3, 2022

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

  • VS Code Version: 1.73.0 (Universal)
  • OS Version: macOS 13.0 (arm64)

Context

We are maintaining TypeScript projects across multiple repositories with one repository being the primary framework that provides the majority of the functionality. For historic reasons we are using an AMD-based module bundler (require.js) that expects fully qualified paths for module dependencies.

Project Configuration

We are referencing this main project in the package.json using a commit id like this:

{
  "dependencies": {
    "@woltlab/wcf": "https://github.com/WoltLab/WCF.git#f8ba2b43c7fcc6428d61e5c9a31211e46db7f265"
  }
}

In the tsconfig.json we have set up a path wildcard to map references to modules from the primary repository:

{
  "include": [
    "node_modules/@woltlab/wcf/global.d.ts",
    "ts/**/*"
  ],
  "compilerOptions": {
    "module": "amd",
    "rootDir": "ts/",
    "baseUrl": ".",
    "paths": {
      "*": [
        "node_modules/@woltlab/wcf/ts/*"
      ]
    }
  }
}

Observed Behavior

The auto import works, but the generated import expands it to the entire path.

import { dialogFactory } from "@woltlab/wcf/ts/WoltLabSuite/Core/Component/Dialog";

Expected Behavior

Auto imports should be referenced using their full path, but not expanding it to the full path:

import { dialogFactory } from "WoltLabSuite/Core/Component/Dialog";

It is important to note that the TypeScript compiler will correctly resolve and validate the above dependency. This will also generate valid AMD dependencies that can be resolved by our module bundler.

@mjbvz mjbvz transferred this issue from microsoft/vscode Nov 3, 2022
@mjbvz mjbvz removed their assignment Nov 3, 2022
@RyanCavanaugh RyanCavanaugh added the Needs More Info The issue still hasn't been fully clarified label Nov 18, 2022
@RyanCavanaugh
Copy link
Member

Can you set up a sample repo we can clone? There are a bunch of other factors that go into this we'd need to investigate further

@dtdesign
Copy link
Author

Thanks for taking your time @RyanCavanaugh! I have provided a simple reproducer repository that showcases the problem:

https://github.com/dtdesign/typescript-issue-51398

How to reproduce the issue:

  1. Clone the repository.
  2. Run npm i which will install both TypeScript and the source repository for the imports.
  3. Open the repository in VSCode.
  4. Edit the file src/test.ts.
  5. Attempt to import dialogFactory and compare the generated import to the existing import of confirmationFactory.

@RyanCavanaugh
Copy link
Member

Thanks for setting that up - it's much clearer in that form. I haven't cloned this yet, but looking at the tree, it looks like you may need to set your "auto import" preference to "non-relative". AI always prefers names that look like properly-qualified module reference over those that come in via baseUrl, even if they're longer. Does changing the preference to "non-relative" create the expected behavior?

image

@dtdesign
Copy link
Author

I’ve tried both “non-relative” and “project-relative”, but none of them appear to make a difference. In addition, I have repeated the changes, but with a restart of VSCode each time, just to make sure nothing got stuck. The IDE was previously set up with the default value of “shortest”.

I have tested the behavior for the same import of dialogFactory in the referenced repository itself, another repository that belongs to us as well as inside the test repository I have set up for this issue.

@dtdesign
Copy link
Author

dtdesign commented Feb 8, 2023

May I ask if there is anything else I can provide to help you to identify the cause of this issue?

@RyanCavanaugh RyanCavanaugh removed the Needs More Info The issue still hasn't been fully clarified label Aug 8, 2024
@RyanCavanaugh RyanCavanaugh added Needs Investigation This issue needs a team member to investigate its status. Domain: Auto-import labels Aug 8, 2024
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 5.7.0 milestone Aug 8, 2024
@RyanCavanaugh
Copy link
Member

Reconfirmed the repro on 5.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Domain: Auto-import Needs Investigation This issue needs a team member to investigate its status.
Projects
None yet
Development

No branches or pull requests

4 participants