Skip to content

Allow blacklisting paths in auto import suggestions #47061

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

Closed
5 tasks done
chriswoodie opened this issue Dec 8, 2021 · 3 comments
Closed
5 tasks done

Allow blacklisting paths in auto import suggestions #47061

chriswoodie opened this issue Dec 8, 2021 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@chriswoodie
Copy link

Suggestion

πŸ” Search Terms

  • blacklist path
  • exclude path
  • blacklist auto import path
  • exclude auto import path

βœ… Viability Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

⭐ Suggestion

Allow blacklisting/exclusion of auto import paths.

Here are some possible solutions as I see it:

  • Allow blacklisting/excluding paths for auto imports
  • Suggest all possible paths and let the developer choose which path is correct

πŸ“ƒ Motivating Example

In certain scenarios, such as when using a monorepo with Angular and Nx, you will have an index.ts file for your libraries which acts as the entry point. This creates huge issues when using project-relative imports in VSC, as it suggests the index.ts file instead of the actual file when working with imports that are inside the same library. Using the index.ts file will cause any app consuming the library to crash due to what I assume are circular dependencies.

Here I expect to get ../../helpers/global/is-external-url instead of ../../../index:

Screenshot 2021-12-07 at 11 08 30

πŸ’» Use Cases

What do you want to use this for?
See above explanation.

What shortcomings exist with current approaches?
It's really easy to mess up without knowing what is wrong, and there isn't a way to solve this currently as far as I'm aware.

What workarounds are you using in the meantime?

  • Added an ESLint rule that shows an error when using an index.ts import, still doesn't prevent compilation so you might not even notice that you have an error until you try to build (assuming you have ESLint check enabled when building)
  • Using "Quick Fix" and then choosing the correct import path there, but this is annoying and wastes your time. The correct path should show up when typing.
@fatcerberus
Copy link

Basically the same issue as #45953.

@RyanCavanaugh
Copy link
Member

Yeah, duplicate of either that one or #35395 depending on the use case

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Dec 9, 2021
@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants